Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

James Robertson http://www.r0bertson.co.uk

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Configuring Asterisk as a Jabber client

Here's my working instructions to connect my Asterisk box as a client to my Jabber server. When a call comes in on extension 10 a message is sent to me.


file: jabber.conf
[general]
debug=yes                               ;;Turn on debugging by default.
autoprune=no                            ;;Auto remove users from buddy list.
autoregister=yes                        ;;Auto register users from buddy list. 

[asterisk]                              ;;label
type=client                             ;;Client or Component connection
serverhost=jamesrobertson.eu
                                        ;;      talk.google.com
username=asterisk@jamesrobertson.eu/Home        ;;Username with optional roster.

secret=XXXXXXXX                         ;;Password
port=5222                               ;;Port to use defaults to 5222
usetls=no                               ;;Use tls or not
;usesasl=yes                            ;;Use sasl or not
buddy=james@jamesrobertson.eu
statusmessage="I am available"          ;;Have custom status message for
                                        ;;Asterisk.
timeout=100                             ;;Timeout on the message stack.


file: extensions.conf
exten => 10,1,JABBERSend(asterisk,james@jamesrobertson.eu, Call from ${CALLERID(name)} at number <${CALLERID(num)}> on ${STRFTIME(,GMT-1,%A %B %d %G at %l:%M:%S %p)} )
exten => 10,n,Macro(stdexten,100,100)



output (observed in my chat window from user Asterisk)
Call from Line 1 - Home at number <6200> on Sunday May 18 2008 at 8:53:24 PM

Using XMPP4R-Simple to check for activity.

Using XMPP4R--Simple these Ruby code snippets show a user's status change and any messages they may have sent you since the last time.

# user1 changes their status to away
jabber.presence_updates do |friend, old_presence, new_presence|
  puts "Received presence update from #{friend.to_s}: #{new_presence}"
end

# user1 sends the message "do you like Tofu?"
jabber.received_messages do |message|
  puts "Received message from #{message.from}: #{message.body}"
end



Reference: http://xmpp4r-simple.rubyforge.org/

Sending a message using XMPP and Ruby

This Ruby code shows how to send an instant message through XMPP [wikipedia.org] using XMPP4R [gna.org]. Source code origin: Ruby and XMPP/Jabber Part 2: Logging in and sending simple messages [famundo.com].

Preparation
- Installed eJabberd on my Gentoo server
- Created 2 user accounts using Pidgin Internet Messenger on my Ubuntu desktop.
- Tested sending messages using Jabber Instant Messaging (Gabber) and Pidgin Internet Messenger.

Installation
gem install xmpp4r

What we will need
require 'rubygems'
require 'xmpp4r'
include Jabber

Logging in
jid = JID::new('yourname@yourdomain.com/Testing')
password = 'yourpassword'
cl = Client::new(jid)
cl.connect
cl.auth(password)

Sending a simple message
to = "user2@yourdomain.com"
subject = "XMPP4R test"
body = "Hi, this is my first try from XMPP4R!!!"
m = Message::new(to, body).set_type(:normal).set_id('1').set_subject(subject)
cl.send m

References:
- Building a Twitter Agent with Ruby and Rails [rubyinside.com]
- http://gentoo-wiki.com/Ejabberd

* update 15:45 18-Feb-08 *
Here's a simpler example I found from Liminal Existence: Announcing Jabber::Simple [romeda.org]

sudo gem install xmpp4r-simple
require 'xmpp4r-simple'

jabber = Jabber::Simple.new('yourname@yourdomain.com', 'yourpassword')
jabber.deliver("user1@yourdomain.com", "Hey! I'm thinking of going Vegetarian - Any suggestions?")


see also: IM Integration With XMPP4r : Part 2 [rubyfleebie.com]
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS