julien51 / xmpp2webhooks
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
34aec8d
XMPP 2 Webhook
This is a very simple example to show how easy it is to create a HTTP POST request based on stanzas received by a Jabber Component. You can get this code and run it by yourself, or you can use Babylon to create a similar component that suits your needs.
The HTML response will then be "posted" to the XMPP chat.
Run this Example
You need to have access to a jabber server and set up access for a component that will be dedicated to this gateway. Choose a port and a password and copy them into config/config.yaml
Run with script/component
Then, send IM messages to encoded_url@your_component_jid where :
- encoded_url is a url that you have encoded with the following:
+url.gsub(/[ "&'\/:<>@\\]/) { |c| '\\' + c[0].to_s(16).rjust(2, '0') }+
- your_component_jid is the jid of your component, like xmpp2hooks.server.com
Make sure the URL you use accepts POST requests! For testing/debugging purposes you can use www.postbin.org/
Create your own Component
This example will POST the "from", the "subject" and the "body" of a regular IM chat message. You might want to POST specific information.
- $> sudo gem install babylon
- $> babylon application myapp
- $> cd myapp
- $> babylon controller xmpp2http
post:100://message[@type=’chat’]
- xmpp2http is the name of the controller to be created - post is the name of the action that will be called - 100 is the priority - //message[@type='chat'] is an XPath that matches the stanza you'd like to POST
- Customize the fields you want to keep in your stanza to POST in stanzas/post.rb
- Customize the code of your post action in Xmpp2httpController
And you’re done!
Have fun!
