Class Jabber::Framework::Bot
In: lib/xmpp4r/framework/bot.rb
Parent: Base
XMPPElement ErrorResponse XMPPStanza X IqQuery Message Presence Iq JabberError ComponentAuthenticationFailure ArgumentError SOCKS5Error ServerError NoNameXmlnsRegistered ClientAuthenticationFailure Connection Client Component Client Singleton IdGenerator Comparable JID StandardError REXML::Element Stream IqQuery IqQueryRoster IqQueryBytestreams IqQueryVersion IqQueryRPC IqQueryMUCOwner IqQueryMUCAdmin IqQueryDiscoItems IqQueryDiscoInfo XRosterItem RosterXItem XMPPElement RosterItem StreamHost IqSiFile IqSiFileRange IqSi StreamHostUsed IqFeature C Body HTML UserItem XMUCUserInvite Configuration Items Item IqPubSub Publish Event IqPubSubOwner Subscription Unsubscribe Tune XDataField XDataReported XDataTitle XDataInstructions Feature Item Identity IqVcard XRoster RosterX X XMUC XMUCUser XDelay XData Iq IqCommand SOCKS5Bytestreams SOCKS5BytestreamsTarget SOCKS5BytestreamsInitiator SOCKS5BytestreamsServerStreamHost TCPSocket SOCKS5Socket IBB IBBTarget IBBInitiator Responder SimpleResponder XMLRPC::ParserWriterChooseMixin Client Server XMLRPC::ParseContentType XMLRPC::BasicServer MUCClient SimpleMUCClient MUC::UserItem XMUCUserItem IqQueryMUCAdminItem XParent SubscriptionConfig NodeConfig OwnerNodeConfig EventItems EventItem ServiceHelper NodeHelper Base Anonymous DigestMD5 Plain PubSub::ServiceHelper Helper FileSource Base Bot CallbackList Callback StreamParser Semaphore Helper Responder SOCKS5BytestreamsPeer SOCKS5BytestreamsServer IBBQueueItem Helper MUCBrowser NodeBrowser Helper Responder Helper lib/xmpp4r/message.rb lib/xmpp4r/connection.rb lib/xmpp4r/xmppstanza.rb lib/xmpp4r/iq.rb lib/xmpp4r/callbacks.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/stream.rb lib/xmpp4r/client.rb lib/xmpp4r/jid.rb lib/xmpp4r/x.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/semaphore.rb lib/xmpp4r/errors.rb lib/xmpp4r/component.rb lib/xmpp4r/presence.rb lib/xmpp4r/xmppelement.rb lib/xmpp4r/query.rb lib/xmpp4r/roster/x/roster.rb lib/xmpp4r/roster/helper/roster.rb lib/xmpp4r/roster/iq/roster.rb Roster lib/xmpp4r/command/iq/command.rb lib/xmpp4r/command/helper/responder.rb Command XParent lib/xmpp4r/bytestreams/iq/si.rb lib/xmpp4r/bytestreams/helper/ibb/initiator.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb lib/xmpp4r/bytestreams/iq/bytestreams.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb lib/xmpp4r/bytestreams/helper/ibb/target.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb lib/xmpp4r/bytestreams/helper/ibb/base.rb Bytestreams lib/xmpp4r/version/helper/responder.rb lib/xmpp4r/version/helper/simpleresponder.rb lib/xmpp4r/version/iq/version.rb Version lib/xmpp4r/feature_negotiation/iq/feature.rb FeatureNegotiation lib/xmpp4r/caps/helper/helper.rb lib/xmpp4r/caps/c.rb Caps lib/xmpp4r/rpc/helper/server.rb lib/xmpp4r/rpc/helper/client.rb lib/xmpp4r/rpc/iq/rpc.rb RPC lib/xmpp4r/xhtml/html.rb XHTML lib/xmpp4r/muc/iq/mucadminitem.rb lib/xmpp4r/muc/x/muc.rb lib/xmpp4r/muc/item.rb lib/xmpp4r/muc/helper/simplemucclient.rb lib/xmpp4r/muc/iq/mucadmin.rb lib/xmpp4r/muc/helper/mucbrowser.rb lib/xmpp4r/muc/x/mucuseritem.rb lib/xmpp4r/muc/x/mucuserinvite.rb lib/xmpp4r/muc/iq/mucowner.rb lib/xmpp4r/muc/helper/mucclient.rb MUC lib/xmpp4r/delay/x/delay.rb Delay lib/xmpp4r/pubsub/children/item.rb lib/xmpp4r/pubsub/children/configuration.rb lib/xmpp4r/pubsub/children/subscription.rb lib/xmpp4r/pubsub/helper/servicehelper.rb lib/xmpp4r/pubsub/children/unsubscribe.rb lib/xmpp4r/pubsub/children/publish.rb lib/xmpp4r/pubsub/children/event.rb lib/xmpp4r/pubsub/iq/pubsub.rb lib/xmpp4r/pubsub/helper/nodebrowser.rb lib/xmpp4r/pubsub/helper/nodehelper.rb lib/xmpp4r/pubsub/children/items.rb lib/xmpp4r/pubsub/children/subscription_config.rb lib/xmpp4r/pubsub/children/node_config.rb PubSub lib/xmpp4r/sasl.rb SASL lib/xmpp4r/httpbinding/client.rb HTTPBinding lib/xmpp4r/tune/helper/helper.rb lib/xmpp4r/tune/tune.rb UserTune lib/xmpp4r/dataforms/x/data.rb Dataforms lib/xmpp4r/bytestreams/helper/filetransfer.rb TransferSource FileTransfer lib/xmpp4r/discovery/iq/discoinfo.rb lib/xmpp4r/discovery/helper/responder.rb lib/xmpp4r/discovery/iq/discoitems.rb Discovery lib/xmpp4r/framework/base.rb lib/xmpp4r/framework/bot.rb Framework lib/xmpp4r/vcard/helper/vcard.rb lib/xmpp4r/vcard/iq/vcard.rb Vcard Jabber dot/m_99_0.png

Abstract handler methods that may be implemented by a deriving class:

  • on_message(text)
  • on_message_xhtml(html_body, text)

Methods

Public Class methods

[Source]

    # File lib/xmpp4r/framework/bot.rb, line 30
30:       def initialize(jid, password)
31:         cl = Jabber::Client.new(jid)
32:         cl.connect
33:         cl.auth(password)
34: 
35:         super(cl)
36: 
37:         roster.add_subscription_request_callback do |item,presence|
38:           if accept_subscription_from?(presence.from.strip)
39:             roster.accept_subscription(presence.from.strip)
40:           else
41:             roster.decline_subscription(presence.from.strip)
42:           end
43:         end
44: 
45:         @pep_notifications = []
46:         cl.add_message_callback do |msg|
47:           if msg.type != :error and msg.body
48:             if (html = msg.first_element('html')) and respond_to? :on_message_xhtml
49:               on_message_xhtml(html.body, msg.body)
50:             elsif respond_to? :on_message
51:               on_message(msg.body)
52:             end
53:           elsif msg.type != :error and (event = msg.first_element('event'))
54:             event.each_element('items') do |items|
55:               node = items.attributes['node']
56:               items.each_element('item') do |item|
57:                 @pep_notifications.each { |notification_node,callback|
58:                   if node == notification_node
59:                     callback.call(msg.from, item)
60:                   end
61:                 }
62:               end
63:             end
64:           else
65:             false
66:           end
67:         end
68: 
69:         add_cap('presence')
70:         add_cap(Caps::NS_CAPS)
71:         add_cap('message') if respond_to? :on_message
72:         add_cap(XHTML::NS_XHTML_IM) if respond_to? :on_message_xhtml
73: 
74:         @presence_show = nil
75:         @presence_status = nil
76:       end

Public Instance methods

Front-end for Roster::Helper#add_subscription_request_callback

Can be overwritten, must return true or false

[Source]

    # File lib/xmpp4r/framework/bot.rb, line 89
89:       def accept_subscription_from?(jid)
90:         true
91:       end

Add feature namespace to Capabilities Discovery

[Source]

    # File lib/xmpp4r/framework/bot.rb, line 80
80:       def add_cap(capability)
81:         disco_default.add_feature(capability)
82:         disco_caps.add_feature(capability)
83:       end

[Source]

     # File lib/xmpp4r/framework/bot.rb, line 141
141:       def add_pep_notification(node, &callback)
142:         add_cap("#{node}+notify")
143:         @pep_notifications << [node, callback]
144:       end

Send a simple text chat message

[Source]

     # File lib/xmpp4r/framework/bot.rb, line 95
 95:       def send_message(to, text)
 96:         msg = Message.new
 97:         msg.type = :chat
 98:         msg.to = to
 99:         msg.body = text
100:         @stream.send(msg)
101:       end

Send an XHTML chat message

text:[String] alternate plain text body, generated from xhtml_contents if nil

[Source]

     # File lib/xmpp4r/framework/bot.rb, line 106
106:       def send_message_xhtml(to, xhtml_contents, text=nil)
107:         msg = Message.new
108:         msg.type = :chat
109:         msg.to = to
110:         html = msg.add(XHTML::HTML.new(xhtml_contents))
111:         msg.body = text ? text : html.to_text
112:         @stream.send(msg)
113:       end

Set and send a Presence

[Source]

     # File lib/xmpp4r/framework/bot.rb, line 117
117:       def set_presence(show=nil, status=nil)
118:         @presence_show = show
119:         @presence_status = status
120:         send_presence
121:       end

Private Instance methods

[Source]

     # File lib/xmpp4r/framework/bot.rb, line 125
125:       def send_presence
126:         roster.wait_for_roster
127: 
128:         # TODO: vcard photo hash
129:         if @presence_show == :unavailable
130:           presence = Presence.new(nil, @presence_status)
131:           presence.type = :unavailable
132:         else
133:           presence = Presence.new(@presence_show, @presence_status)
134:         end
135:         presence.add(disco_caps.generate_caps)
136:         @stream.send(presence)
137:       end

[Validate]