Sample XMPP demo for facebook

Ruby code posted by Prudhvi
created at 12 Oct 10:03

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'rubygems'
require 'xmpp4r'


    # Connect to the server and set presence to available for chat.
    puts 'Enter your username with full domain'
    uname = gets
    puts 'Enter your password'
    passwd = gets
    uname = uname.chomp
    passwd = passwd.chomp
    jid = Jabber::JID.new(uname)
    client = Jabber::Client.new(jid)
    client.connect
    client.auth(passwd)
    #client.send(Jabber::Presence.new.set_show(:chat).set_status('Rails!'))
    
    puts 'Enter your friend id to whom you want to send the message'
    toname = gets
    toname = toname.chomp
    # Send an Instant Message.
    puts 'Enter the message you want to send'
    body = gets
    to_jid = Jabber::JID.new(toname)
    message = Jabber::Message::new(to_jid, body).set_type(:chat).set_id('1')
    client.send(message)

  
841 Bytes in 4 ms with coderay