XMPP client with Ruby

Hi all,

Does anyone out there know how to implement an xmpp client to a server
like ejabberd using ruby?

Kindly, give me any links to resources.

···

--

Ochomo
--
Posted via http://www.ruby-forum.com/.

Zablon Ochomo a écrit :

Hi all,

Does anyone out there know how to implement an xmpp client to a server
like ejabberd using ruby?

Kindly, give me any links to resources.

--

Ochomo

There are two xmpp library in the gem repository

Stephane Wirtel wrote:

Zablon Ochomo a �crit :

Hi all,

Does anyone out there know how to implement an xmpp client to a server
like ejabberd using ruby?

Kindly, give me any links to resources.

--

Ochomo

There are two xmpp library in the gem repository

thanks

I had downloaded the xmpp4r gem and installed.

thanks again

···

--
Posted via http://www.ruby-forum.com/\.

Here's a test script I played with awhile ago to pipe the output of a
program to me over jabber using xmpp4r-simple:

require 'rubygems'
require 'highline'
require 'xmpp4r-simple'

hl = HighLine.new

Username = hl.ask("Username: ")
Password = hl.ask("Password: ") { |q| q.echo = "x" }
Notifier = hl.ask("Notifier: ")

Resource = "notificabot"
Server = "XXX"

@jabber = { :username => "#{Username}/#{Resource}@#{Server}",
            :password => "#{Password}" }

@notify = "#{Username}@jabber.ctc.com"

begin
  Signal.trap(:INT) { raise }
  Signal.trap(:TERM) { raise }

  IO.popen(Notifier, "r") do |notifier|
    im = Jabber::Simple.new(@jabber[:username], @jabber[:password])

    begin
      im.status(:dnd, "notificabot")

      notifier.each_line do |line|
        im.deliver(@notify, line.chomp)
        puts line
      end
    rescue
      puts $!.message
    ensure
      im.disconnect
    end
  end
rescue
  puts $!.message
end

···

On Jan 25, 2008 4:47 AM, Zablon Ochomo <ochomoz@gmail.com> wrote:

Stephane Wirtel wrote:
> Zablon Ochomo a �crit :
>> Does anyone out there know how to implement an xmpp client to a server
>> like ejabberd using ruby?
>
> There are two xmpp library in the gem repository

thanks

I had downloaded the xmpp4r gem and installed.

The code below is working with the xmpp4r form
http://home.gna.org/xmpp4r/

   require 'XMPP4R'
  begin
       # Connect to the server and set presence to available for chat.
       jid = Jabber::JID.new('myjid@xmppserver/Resource')
       client = Jabber::Client.new(jid, false)
       client.connect
       client.auth('passwd')
       client.send(Jabber::Presence.new.set_show(:chat).set_status('Ruby!'))

       # Send an Instant Message.
       body = 'Hi XMPP'
       to_jid = Jabber::JID.new('tojid@xmppserver')
       message = Jabber::Message::new(to_jid,
body).set_type(:normal).set_id('1')
       client.send(message)
  end

question:

how do I receive messages, since I can only send?

···

---
ochomo
--
Posted via http://www.ruby-forum.com/.

Try looking at some of the examples. If you installed the gem, then go to:
    .../gems/xmpp4r-0.3.2/data/doc/xmpp4r/examples/

And, look for add_message_callback in the RDoc:
    http://home.gna.org/xmpp4r/rdoc/
    http://home.gna.org/xmpp4r/rdoc/classes/Jabber/Stream.html#M000487

examples/basic/echo_threaded.rb:
    cl = Client::new(myJID)
    cl.connect
    ...
    cl.add_message_callback do |m|
      if m.type != :error
        puts m.body
      end
    end

···

On Jan 28, 2008 2:04 AM, Zablon Ochomo <ochomoz@gmail.com> wrote:

The code below is working with the xmpp4r form
http://home.gna.org/xmpp4r/
...
how do I receive messages, since I can only send?

Something like that, i believe.

client.add_message_callback do |m|
  print "#{m.from} - #{m.body}\n"
end

···

On 1/28/08, Zablon Ochomo <ochomoz@gmail.com> wrote:

how do I receive messages, since I can only send?

Zablon Ochomo wrote:

The code below is working with the xmpp4r form
http://home.gna.org/xmpp4r/

   require 'XMPP4R'
  begin
       # Connect to the server and set presence to available for chat.
       jid = Jabber::JID.new('myjid@xmppserver/Resource')
       client = Jabber::Client.new(jid, false)
       client.connect
       client.auth('passwd')
       client.send(Jabber::Presence.new.set_show(:chat).set_status('Ruby!'))

       # Send an Instant Message.
       body = 'Hi XMPP'
       to_jid = Jabber::JID.new('tojid@xmppserver')
       message = Jabber::Message::new(to_jid,
body).set_type(:normal).set_id('1')
       client.send(message)
  end

question:

how do I receive messages, since I can only send?

---
ochomo

Hi Zablon,

I can send IM to only by setting presence status, But my account have
more than 50 or 100 contacts. It will take long time to set the presence
and getting status message from each contact.

ie,
client.send(Jabber::Presence.new.set_show(:chat).set_status('Ruby!'))
line of code breaks the functionality of client.send(message).

Setting presence took long time, but before to that send message code
executed. If I have to wait for getting result of setting presence and
then running the send message code only results the required output.

Is there any way to send IM without setting Presence.

My sever installed with Openfire and IM gateway plugin. Whether I have
to install any other plugin or source to automatically log into
Transport.

Please give your valuable suggestion.

Regards,
T.Veeraa.

···

--
Posted via http://www.ruby-forum.com/\.

Thanks for your help.

I googled out on xmppr4-simple. It appears to easier and working well.
Here is the code that runs well with ejabberd sever:

require 'rubygems'
require 'xmpp4r-simple'
im = Jabber::Simple.new('zo@myejabberd','zo')

im.deliver('gm@myejabberd','hello xmpp')

puts 'send done'
sleep(3)

im.received_messages { |msg| puts "#{msg.body} #{msg.type}" }

im.disconnect

···

---

ochomo
--
Posted via http://www.ruby-forum.com/.

Veera,
I was only trying out on this code. I didnt go much deep.

I was trying to find a way of communicating between my software modules.
I decided to use ISO 8583 protocol instead.

Sorry, I wish I could help.

Ochomo

Veera Sundaravel wrote:

···

Zablon Ochomo wrote:

The code below is working with the xmpp4r form
http://home.gna.org/xmpp4r/

   require 'XMPP4R'
  begin
       # Connect to the server and set presence to available for chat.
       jid = Jabber::JID.new('myjid@xmppserver/Resource')
       client = Jabber::Client.new(jid, false)
       client.connect
       client.auth('passwd')
       client.send(Jabber::Presence.new.set_show(:chat).set_status('Ruby!'))

       # Send an Instant Message.
       body = 'Hi XMPP'
       to_jid = Jabber::JID.new('tojid@xmppserver')
       message = Jabber::Message::new(to_jid,
body).set_type(:normal).set_id('1')
       client.send(message)
  end

question:

how do I receive messages, since I can only send?

---
ochomo

Hi Zablon,

I can send IM to only by setting presence status, But my account have
more than 50 or 100 contacts. It will take long time to set the presence
and getting status message from each contact.

ie,
client.send(Jabber::Presence.new.set_show(:chat).set_status('Ruby!'))
line of code breaks the functionality of client.send(message).

Setting presence took long time, but before to that send message code
executed. If I have to wait for getting result of setting presence and
then running the send message code only results the required output.

Is there any way to send IM without setting Presence.

My sever installed with Openfire and IM gateway plugin. Whether I have
to install any other plugin or source to automatically log into
Transport.

Please give your valuable suggestion.

Regards,
T.Veeraa.

--
Posted via http://www.ruby-forum.com/\.

Hi Zablon,

When I am running your code i am getting error:

c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.1/lib/xmpp4r/connection.rb:53:in
`init
ialize': Bad file descriptor - connect(2) (Errno::EBADF)
        from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.1/lib/xmpp4r/connection.r
b:53:in `new'
        from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.1/lib/xmpp4r/connection.r
b:53:in `connect'
        from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.1/lib/xmpp4r/client.rb:73
:in `connect'
        from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.1/lib/xmpp4r/client.rb:60
:in `connect'
        from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.1/lib/xmpp4r/client.rb:58
:in `each'
        from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.1/lib/xmpp4r/client.rb:58
:in `connect'
        from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.4/lib/xmpp4r-simpl
e.rb:371:in `connect!'
        from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.4/lib/xmpp4r-simpl
e.rb:309:in `client'
        from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.4/lib/xmpp4r-simpl
e.rb:318:in `send!'
        from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.4/lib/xmpp4r-simpl
e.rb:134:in `status'
        from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.4/lib/xmpp4r-simpl
e.rb:85:in `initialize'
        from gtalk123.rb:3:in `new'
        from gtalk123.rb:3

Can you please help.

Regards
Lokesh Agrawal

Zablon Ochomo wrote:

···

Thanks for your help.

I googled out on xmppr4-simple. It appears to easier and working well.
Here is the code that runs well with ejabberd sever:

require 'rubygems'
require 'xmpp4r-simple'
im = Jabber::Simple.new('zo@myejabberd','zo')

im.deliver('gm@myejabberd','hello xmpp')

puts 'send done'
sleep(3)

im.received_messages { |msg| puts "#{msg.body} #{msg.type}" }

im.disconnect

---

ochomo

--
Posted via http://www.ruby-forum.com/\.

Hi Zablon,

No problem, thanks for instant reply. If I can solve the issue, I'l keep
you posted.

Regards,
T.Veeraa.

···

--
Posted via http://www.ruby-forum.com/.

Veera Sundaravel wrote:

Hi Zablon,

No problem, thanks for instant reply. If I can solve the issue, I'l keep
you posted.

Regards,
T.Veeraa.

Hi,

I am trying to send some message over the gtalk, here is my code

require 'rubygems'
require 'xmpp4r-simple'

jabber = Jabber::Simple.new('lareb.indore@gmail.com','my_passwrd')

but I am getting this error

···

-------------------------------------------------------------
`initialize': A connection attempt failed because the connected party
did not properly respond after a period of time, or established
connection failed because connected host has failed to respond. -
connect(2) (Errno::ETIMEDOUT)
  from
E:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.5/lib/xmpp4r/connection.rb:66:in
`new'
  from
E:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.5/lib/xmpp4r/connection.rb:66:in
`connect'
  from
E:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.5/lib/xmpp4r/client.rb:70:in
`connect'
  from
E:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.8/lib/xmpp4r-simple.rb:394:in
`connect!'
  from
E:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.8/lib/xmpp4r-simple.rb:322:in
`client'
  from
E:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.8/lib/xmpp4r-simple.rb:331:in
`send!'
  from
E:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.8/lib/xmpp4r-simple.rb:147:in
`status'
  from
E:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.8/lib/xmpp4r-simple.rb:90:in
`initialize'
--------------------------------------------------------------
can u plz help me, I really need this.

Thanks,
Lareb Nawab
--
Posted via http://www.ruby-forum.com/\.