### Home Classes Methods

### In Files

- lib/xmpp4r/framework/bot.rb

### Parent

Jabber::Framework::Base

### Methods

- ::new
- #accept_subscription_from?
- #add_cap
- #add_pep_notification
- #send_message
- #send_message_xhtml
- #set_presence

### Files

- CHANGELOG
- COPYING
- LICENSE
- README.rdoc
- README_ruby19.txt

### Class/Module Index

Quicksearch

- Jabber
- Jabber::ArgumentError
- Jabber::Bytestreams
- Jabber::Bytestreams::IBB
- Jabber::Bytestreams::IBBInitiator
- Jabber::Bytestreams::IBBQueueItem
- Jabber::Bytestreams::IBBTarget
- Jabber::Bytestreams::IqQueryBytestreams
- Jabber::Bytestreams::IqSi
- Jabber::Bytestreams::IqSiFile
- Jabber::Bytestreams::IqSiFileRange
- Jabber::Bytestreams::SOCKS5Bytestreams
- Jabber::Bytestreams::SOCKS5BytestreamsInitiator
- Jabber::Bytestreams::SOCKS5BytestreamsPeer
- Jabber::Bytestreams::SOCKS5BytestreamsServer
- Jabber::Bytestreams::SOCKS5BytestreamsServerStreamHost
- Jabber::Bytestreams::SOCKS5BytestreamsTarget
- Jabber::Bytestreams::SOCKS5Socket
- Jabber::Bytestreams::StreamHost
- Jabber::Bytestreams::StreamHostUsed
- Jabber::Callback
- Jabber::CallbackList
- Jabber::Caps
- Jabber::Caps::C
- Jabber::Caps::Helper
- Jabber::Client
- Jabber::ClientAuthenticationFailure
- Jabber::Command
- Jabber::Command::IqCommand
- Jabber::Command::Responder
- Jabber::Component
- Jabber::ComponentAuthenticationFailure
- Jabber::Connection
- Jabber::Connection::SSLSocketUTF8
- Jabber::Dataforms
- Jabber::Dataforms::XData
- Jabber::Dataforms::XDataField
- Jabber::Dataforms::XDataInstructions
- Jabber::Dataforms::XDataReported
- Jabber::Dataforms::XDataTitle
- Jabber::Delay
- Jabber::Delay::XDelay
- Jabber::Discovery
- Jabber::Discovery::Feature
- Jabber::Discovery::Helper
- Jabber::Discovery::Identity
- Jabber::Discovery::IqQueryDiscoInfo
- Jabber::Discovery::IqQueryDiscoItems
- Jabber::Discovery::Item
- Jabber::Discovery::Responder
- Jabber::EntityTime
- Jabber::EntityTime::IqTime
- Jabber::EntityTime::Responder
- Jabber::ErrorResponse
- Jabber::FeatureNegotiation
- Jabber::FeatureNegotiation::IqFeature
- Jabber::FileTransfer
- Jabber::FileTransfer::FileSource
- Jabber::FileTransfer::Helper
- Jabber::FileTransfer::TransferSource
- Jabber::Framework
- Jabber::Framework::Base
- Jabber::Framework::Bot
- Jabber::HTTPBinding
- Jabber::HTTPBinding::Client
- Jabber::IdGenerator
- Jabber::InvalidChatState
- Jabber::Iq
- Jabber::IqQuery
- Jabber::JID
- Jabber::JabberError
- Jabber::LastActivity
- Jabber::LastActivity::Helper
- Jabber::LastActivity::IqQueryLastActivity
- Jabber::MUC
- Jabber::MUC::IqQueryMUCAdmin
- Jabber::MUC::IqQueryMUCAdminItem
- Jabber::MUC::IqQueryMUCOwner
- Jabber::MUC::MUCBrowser
- Jabber::MUC::MUCClient
- Jabber::MUC::SimpleMUCClient
- Jabber::MUC::UserItem
- Jabber::MUC::XMUC
- Jabber::MUC::XMUCUser
- Jabber::MUC::XMUCUserInvite
- Jabber::MUC::XMUCUserItem
- Jabber::Message
- Jabber::NoNameXmlnsRegistered
- Jabber::NotConnected
- Jabber::Observable
- Jabber::Observable::Contact
- Jabber::Observable::PubSub
- Jabber::Observable::PubSub::AlreadySet
- Jabber::Observable::PubSub::NoService
- Jabber::Observable::Subscriptions
- Jabber::Presence
- Jabber::PubSub
- Jabber::PubSub::Configuration
- Jabber::PubSub::Event
- Jabber::PubSub::EventItem
- Jabber::PubSub::EventItems
- Jabber::PubSub::IqPubSub
- Jabber::PubSub::IqPubSubOwner
- Jabber::PubSub::Item
- Jabber::PubSub::Items
- Jabber::PubSub::NodeBrowser
- Jabber::PubSub::NodeConfig
- Jabber::PubSub::NodeHelper
- Jabber::PubSub::OAuthPubSubStreamHelper
- Jabber::PubSub::OAuthServiceHelper
- Jabber::PubSub::OwnerNodeConfig
- Jabber::PubSub::Publish
- Jabber::PubSub::Retract
- Jabber::PubSub::ServiceHelper
- Jabber::PubSub::Subscription
- Jabber::PubSub::SubscriptionConfig
- Jabber::PubSub::Unsubscribe
- Jabber::RPC
- Jabber::RPC::Client
- Jabber::RPC::IqQueryRPC
- Jabber::RPC::Server
- Jabber::Reliable
- Jabber::Reliable::Connection
- Jabber::Reliable::Listener
- Jabber::Roster
- Jabber::Roster::Helper
- Jabber::Roster::Helper::RosterItem
- Jabber::Roster::IqQueryRoster
- Jabber::Roster::RosterItem
- Jabber::Roster::RosterX
- Jabber::Roster::RosterXItem
- Jabber::Roster::XRoster
- Jabber::Roster::XRosterItem
- Jabber::SASL
- Jabber::SASL::Anonymous
- Jabber::SASL::Base
- Jabber::SASL::DigestMD5
- Jabber::SASL::Plain
- Jabber::SOCKS5Error
- Jabber::Semaphore
- Jabber::ServerDisconnected
- Jabber::Stream
- Jabber::Stream::ThreadBlock
- Jabber::StreamParser
- Jabber::Test
- Jabber::Test::ListenerMocker
- Jabber::UserLocation
- Jabber::UserLocation::Helper
- Jabber::UserLocation::Location
- Jabber::UserTune
- Jabber::UserTune::Helper
- Jabber::UserTune::Tune
- Jabber::Vcard
- Jabber::Vcard::Helper
- Jabber::Vcard::IqVcard
- Jabber::Version
- Jabber::Version::IqQueryVersion
- Jabber::Version::Responder
- Jabber::Version::SimpleResponder
- Jabber::X
- Jabber::XHTML
- Jabber::XHTML::Body
- Jabber::XHTML::HTML
- Jabber::XMPPElement
- Jabber::XMPPStanza
- Jabber::XParent
- REXML
- REXML::Element
- REXML::IOSource
- XMLRPC
- XMLRPC::Create
- Base64
- ObservableThing
- QObserver
- ThreadStore

No matching classes.

# Jabber::Framework::Bot

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

- on_message(text)

- on_message_xhtml(html_body, text)

### Public Class Methods

new(jid, password) click to toggle source

    # File lib/xmpp4r/framework/bot.rb, line 30
    def initialize(jid, password)
      cl = Jabber::Client.new(jid)
      cl.connect
      cl.auth(password)

      super(cl)

      roster.add_subscription_request_callback do |item,presence|
        if accept_subscription_from?(presence.from.strip)
          roster.accept_subscription(presence.from.strip)
        else
          roster.decline_subscription(presence.from.strip)
        end
      end

      @pep_notifications = []
      cl.add_message_callback do |msg|
        if msg.type != :error and msg.body
          if (html = msg.first_element('html')) and respond_to? :on_message_xhtml
            on_message_xhtml(html.body, msg.body)
          elsif respond_to? :on_message
            on_message(msg.body)
          end
        elsif msg.type != :error and (event = msg.first_element('event'))
          event.each_element('items') do |items|
            node = items.attributes['node']
            items.each_element('item') do |item|
              @pep_notifications.each { |notification_node,callback|
                if node == notification_node
                  callback.call(msg.from, item)
                end
              }
            end
          end
        else
          false
        end
      end

      add_cap('presence')
      add_cap(Caps::NS_CAPS)
      add_cap('message') if respond_to? :on_message
      add_cap(XHTML::NS_XHTML_IM) if respond_to? :on_message_xhtml

      @presence_show = nil
      @presence_status = nil
    end

### Public Instance Methods

accept_subscription_from?(jid) click to toggle source

Front-end for Roster::Helper#add_subscription_request_callback

Can be overwritten, must return true or false

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

add_cap(capability) click to toggle source

Add feature namespace to Capabilities Discovery

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

add_pep_notification(node, &callback) click to toggle source

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

send_message(to, text) click to toggle source

Send a simple text chat message

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

send_message_xhtml(to, xhtml_contents, text=nil) click to toggle source

Send an XHTML chat message

text

String

  alternate plain text body, generated from xhtml_contents if nil

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

set_presence(show=nil, status=nil) click to toggle source

Set and send a Presence

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.