[Asterisk-Dev] presence and IM again, want to develop a working "hack"

John Todd jtodd at loligo.com
Mon Jul 4 14:04:25 MST 2005


At 2:13 PM -0300 on 7/4/05, Joshua Colp wrote:
>Greetings,
>
>I'm presently working on Messaging and Presence solutions in Asterisk for
>the Google Summer of Code program. I should have a public site/CVS server so
>people who wish to venture into trying it out can download it soon. As for
>presence itself, cvs head sorta kinda supports it... It's hard to explain.
>
>- Joshua Colp.

Here are some ideas which I came up with a while ago with regards to interworking with other IM/presence engines.  The person that I gave these to didn't do anything with them - anyone is free to take ideas away from this discussion and do something with them; I just want to see my Asterisk phone status in my AIM status... is that so much to ask?  The libraries for all this stuff exist already; it's just a matter of re-writing the concepts so they're no longer GPL.


=====================

This is really a one-way presence idea at the moment.  There are the glimmerings of two-way presence (see the "activewhen" keyword) but this is mostly for CTI outbound notices from an * server to humans upon some events defined by the administrator.  I would see this most typically used either as a screenpop on an inbound or outbound call, or perhaps as a voicemail notification tool if the administrator is clever enough to embed a URL into the string for the instant message text. 


Phase 1: Create a set of programs for Asterisk which allows status checking of a particular username on a particular instant messaging system (availability, idle time) and also allows for transmission of instant messages from Asterisk to other users on those instant messaging systems (one-way.)  The first systems that come to mind would be AOL's AIM and Yahoo.

Phase 2: Add additional instant message systems: maybe Jabber, MSN.  Allow examination of user's header line (in AOL, at least) and pass that through the app_imstatus return codes.  This would allow me to specify "mobile:" as the first digits of my status, thus a GotoIf would be able to know that it should send calls to my cell phone.  Or when I get to work, and shift between my home account ("home: hello, I'm home") to work ("work: at my desk") then the system will automatically forward calls appropriately.  This might be easy enough to do in Phase 1, but I'm uncertain.

Future paths:
  A true "presence" application for telephony in a large scale method is lacking today.  It may be the case that this could be done by creating a custom telephony presence presentation application that is based on an existing (or multiple existing) chat protocols.   As an example, it is possible that I might be able to make my status message on AIM change from "avail/sip:12156667777 at 128.151.224.17" to "busy/sip:12156667777 at 128.151.224.17" every time I pick up the phone; that could be done programmatically by Asterisk.  Then, my friends who have the custom telephony presence application would see the little icon beside "pinkycaruthers" go from green to flashing orange.  As soon as I went back to non-busy, they could just click on my icon, and two things would happen: a password-protected message would get fired off to THEIR phone system and extension from the presence application on their desktop, which in turn would be received by an asterisk-aware application on their Asterisk server, which in turn would create a spool call to MY phone system from the SIP URI that I included in my Status message.   Presto!  We have minimalist call routing, presence, and click-to-dial - we're just missing the little app to do it on <Windows, MacOS, Linux, Java, whatever>.   The core message transport protocols all exist; it's just a matter of layers on top of them.  Using standard telephony URI's, we could not just do this with SIP, but with tel, h323, iax2, anything - it's not limited to VoIP.



; im.conf
;
; Use of this file implies that you have an active account with one or more
;  instant messaging services, and that you probably use an account that is
;  dedicated to your Asterisk server so it "knows" what's going on.  You may
;  need to ensure that any other user id's that you expect to receive messages
;  are filtered in such a way that the messages from your Asterisk-specific
;  account are permitted through.
;
; username=  username of the user on this particular messaging system.
; secret=    password for the username
; type=      type of connection this is.  Each messaging system uses it's own protocols,
;             so we need to specify which one of the protocols we're using for this particular
;             "channel".  Current choices are:
;              aim   - the AOL OSCAR protocol
;              yahoo - the Yahoo protocol
; statusmessage= Sets the status message for the user on the chat server.  Visible to other users.
; activewhen= perform a login only when this channel type is valid or logged in.  This is
;             reduce unnecessary heartbeat traffic for phones that aren't logged in.
;             An example of this setting would be "IAX2/12345" or "SIP/jimmy" where those
;             channel peers would be sending REGISTER messages to the server.
;             Use of keyword "always" means logged in all the time.  Optional.
; subscribe= users whose presence should be monitored by this peer
; port=      port for protocol (defaults taken from type=)
; host=      host for protocol (defaults taken from type=)
;
;
[aim-1]
username=pinkys-asterisk
secret=foofoofoo
type=aim
statusmessage="Pinky Caruthers Phone Presense Robot - no inbound, please."
subscribe=buckaroo,janedoe,turtlehead,misspiggy2001
;
; end im.conf sample


-= Info about application 'IMStatus' =-

[Synopsis]:
Get the status of a remote user's instant messaging presence

[Description]:
  IMStatus(template/remoteuser,[options])
Returns several strings as result codes if successful.  If an error occurs during
transmission, the system will jump to priority n+101.
    ${IM-STATUS}: "online", "offline", "unknown", "idle"
    ${IM-IDLETIME}: number of seconds of idle time
    ${IM-STATUS}: if applicable, the text string of the remote user's status bar
    ${IM-LASTSEEN}: how many minutes ago was this user online, at least as far as
      this running instance of Asterisk has knowledge.  0=online or never
Note that the remoteuser must be in the "subscribe" list of the IM peer in order for
the system to return correct values.  If the IM peer username is listed as the
remoteuser, the status of the IM peer will be returned in ${IM-STATUS} as either
"online" or "offline" depending on the current registered state.

The option string may contain zero or more of the following:
    'g' -- goes on in context if an error occurs
    'W(x)' -- Wait x milliseconds before returning regardless of result (avoids hangs)
 


-= Info about application 'IMSend' =-

[Synopsis]:
Transmit an Instant Message

[Description]:
   IMSend(template/remoteuser/string)
Sends a string to a remote user, using the username in the peer definition as the sender.
Receiver can be any user on the IM network chosen.  Errors are currently handled silently.
String can be up to XXX characters long.



command-line options:
im show peers  = shows a list of IM peers, and statuses of subscription to those peers

im show subscribed [peername][|subscriber] = shows a list of users whose status the system is monitoring, or optionally just one out of the list for that IM peer.  Also shows last time (minutes ago) the user was seen online (0 if online or never)

im debug = debugs instant messaging items

im debug intense = more debug



foo*CLI> im show peers
Name        Type      Host           Port    User          Status
aim1        AIM       64.12.24.32    5190    pinkys-asteri Registered

foo*CLI> im show subscribed aim1
Name        Status      Idle     Lastseen
buckaroo    online      140      0
janedoe     online      3        0
turtlehead  offline     0        0
misspiggy20 offline     0        500



typical trivial usage:

; Send calls to Buckaroo appropriately based on his
;  AIM presence, and send a message before the call
;  if he's on-line
;
exten => 1233,1,AGI(get-customer-data-from-callerid.agi)
exten => 1233,2,SetVar(CALLMESSAGE="${CUSTOMER-NAME} is calling from ${CUSTOMER-COMPANY}.  They do ${BILLABLE-VOLUME} in sales with us - pick up the phone!")
exten => 1233,3,IMStatus(aim1/buckaroo)
exten => 1233,4,GotoIf($[${IM-STATUS} = offline]?5:10)
exten => 1233,5,Dial(Zap/1/${BUCKAROO-CELL})
exten => 1234,6,Hangup
exten => 1234,10,GotoIf($[${IM-STATUS} = online]?11:20)
exten => 1234,11,IMSend(aim1/buckaroo/${CALLMESSAGE})
exten => 1234,12,Dial(SIP/${BUCKAROO-MAIN},20)
exten => 1234,13,Voicemail(u${BUCKAROO-MAIN})
exten => 1234,14,Hangup
exten => 1234,20,Voicemail(${BUCAROO-MAIN})
exten => 1234,21,Hangup



More information about the asterisk-dev mailing list