Hey, guys,
I’m trying to send rich text like html to other protocols with IM Gateway plugin. But I found tt it doesn’t work.
require 'xmpp4r/client’
include Jabber
Login
jid = JID::new(‘blah@localhost’)
cl = Client::new(jid)
cl.connect
cl.auth(‘blahblah’)
Create a message
If I replaced this with “to= ‘foobar@localhost’”, the rich text works properly, so I doubt it’s the problem of IM Gateway
to = “ninja\40gmail.com@gtalk.localhost”
body="Your IM doesn’t support rich text now."
m = Message::new(to, body).set_type(:normal).set_id(‘1’)
Create the html part
h = REXML::Element::new(“html”)
h.add_namespace(‘http://jabber.org/protocol/xhtml-im’)
The body part with the correct namespace
b = REXML::Element::new(“body”)
b.add_namespace(‘http://www.w3.org/1999/xhtml’)
The html itself
t = REXML::Text.new( “This is so COOL!!!. I can really do HTML now.”, false, nil, true, nil, %r/.^/ )
Add the html text to the body, and the body to the html element
b.add(t)
h.add(b)
Add the html element to the message
m.add_element(h)
Send it
cl.send m