hubot-genesys-cloud
Version:
Genesys Cloud adapter for Hubot
84 lines (59 loc) • 2.4 kB
text/coffeescript
Controller = require './framework/Controller.coffee'
module.exports = class RosterController extends Controller
:
getRoster: (callback) ->
.debug 'roster', 'getRoster called',
if then return callback null,
unless
= true
.debug 'roster', 'waiting for roster'
'roster', =>
.debug 'roster', 'returning roster'
callback null,
addToRoster: (jid, callback) ->
console.error 'not implemented'
callback 'not implemented'
removeFromRoster: (jid, callback) ->
console.error 'not implemented'
callback 'not implemented'
: ['rosterItem']
:
rosterResult: (stanza) -> stanza.is('iq') and stanza.getChild('query', "jabber:iq:roster")? and stanza.attrs.type is 'result'
rosterUpdate: (stanza) -> stanza.is('iq') and stanza.getChild('query', "jabber:iq:roster")? and stanza.attrs.type is 'set'
constructor: ->
super
= null
.on 'disconnect', =>
= null
= false
.on 'connect', =>
if then
rosterResult: (stanza) ->
.debug 'roster', 'message', stanza.toString()
= {}
query = stanza.getChild('query', "jabber:iq:roster")
for item in query.getChildren 'item'
{jid, name} = item.attrs
[jid] = {name, jid}
'rosterItem', {name, jid, section:'favorites', type:'person', event:'add'}
'roster'
rosterUpdate: (stanza) ->
.debug 'roster', 'message', stanza.toString()
= {}
query = stanza.getChild('query', "jabber:iq:roster")
for item in query.getChildren 'item'
{jid, name, subscription} = item.attrs
if subscription in ['to', 'both']
[jid] = {name, jid}
'rosterItem', {name, jid, section:'favorites', type:'person', event:'add'}
else if subscription in ['remove', 'none']
delete [jid]
'rosterItem', {name, jid, section:'favorites', type:'person', event:'remove'}
_sendRequest: ->
unless .connected then return .once 'connected', =>
if .features['orgspan:roster'] and !.discovered then return
iq = new ltx.Element 'iq', type:'get', from:.jid.toString()
iq.c 'query', xmlns:'jabber:iq:roster'
.send iq