|
1 |
| -mod_http_offline |
2 |
| -================ |
| 1 | +Ejabberd 16.08 module to send offline user's message via POST request to target URL. |
| 2 | +The main motivation for this module is to use it with push notifications. The request body is in JSON format. See the example below. |
3 | 3 |
|
4 |
| -Ejabberd module to send a post if users was offline. |
5 | 4 |
|
| 5 | +Installation |
| 6 | +------------ |
6 | 7 |
|
7 |
| -This module is based on [Adam Duke mod_interact](https://github.com/adamvduke/mod_interact), [Jason Rowe's post](http://jasonrowe.com/2011/12/30/ejabberd-offline-messages/) and a lot of pieces of code and tips from the web to adapts to work with Ejabber 14.12. |
| 8 | +1. Clone the repository into your Ejabberd's modules sources' folder. On Mac OS X, this folder is `~/.ejabberd-modules/sources/`. |
| 9 | +2. Run command: `ejabberdctl module_install mod_offline_http_post` |
8 | 10 |
|
9 |
| -Installing |
10 |
| ----------- |
| 11 | +That's it. The module is now installed. |
11 | 12 |
|
12 |
| -Clone this repository: |
| 13 | +Configuration |
| 14 | +------------- |
13 | 15 |
|
14 |
| -``` git clone git@github.com:raelmax/mod_http_offline.git``` |
| 16 | +Add the following to ejabberd configuration under `modules:` |
15 | 17 |
|
16 |
| -Change the ```'[your-url-here]'``` string in ```mod_http_offline.erl``` file. |
| 18 | +``` |
| 19 | +mod_offline_http_post: |
| 20 | + auth_token: "secret" |
| 21 | + post_url: "http://example.com/notify" |
| 22 | +``` |
17 | 23 |
|
18 |
| -To compile this I downloaded the code at my home directory and run: |
| 24 | +- auth_token - user defined, hard coded token that will be sent as part of the request's body. Use this token on the target server to validate that the request arrived from a trusted source. |
| 25 | +- post_url - the server's endpoint url |
19 | 26 |
|
20 |
| -``` |
21 |
| - erlc -I /lib/ejabberd/include/ -pa ~/ejabberd/deps/lager/ebin/ mod_http_offline.erl |
| 27 | +Example of the outgoing request: |
| 28 | +-------------------------------- |
| 29 | + |
| 30 | +``` |
| 31 | +{'to':'user2','from':'user1','body':'hi there!','message_id':'purple9ca5e35b','access_token':'secret'} |
22 | 32 | ```
|
23 | 33 |
|
24 |
| -Move the .beam file to ejabberd ebin folder: |
| 34 | +Build and extend this module |
| 35 | +---------------------------- |
25 | 36 |
|
26 |
| -``` |
27 |
| - sudo mv mod_http_offline.beam /lib/ejabberd/ebin/ |
| 37 | +The assumption is that you're developing on Mac OS X and installed Ejabberd via homebrew. |
| 38 | +To build this module for development use the script `build.sh`. Please note that this script is configured to Ejabberd installation on Mac OS X. For other OS, you'll have to modify the dependencies path to point to your Ejabberd installation. |
| 39 | + |
| 40 | +build.sh |
| 41 | +``` |
| 42 | +/usr/local/Cellar/ejabberd/16.08/lib/lager-3.2.1/ebin/ |
| 43 | +/usr/local/Cellar/ejabberd/16.08/lib/fast_xml-1.1.14/ebin/ |
28 | 44 | ```
|
29 | 45 |
|
30 |
| -Add "mod_http_offline" to your ejabberd.yml config at "modules" section: |
| 46 | + You will also need to modify the path of Ejabberd `include` folder in `Emakefile`. |
31 | 47 |
|
32 | 48 | ```
|
33 |
| - mod_http_offline: {} |
| 49 | +{'src/mod_offline_http_post', [{outdir, "ebin"},{i,"/usr/local/Cellar/ejabberd/16.08/lib/ejabberd-16.08/include"}]}. |
34 | 50 | ```
|
35 | 51 |
|
36 |
| -Restart ejabberd! \o/ |
37 |
| - |
38 |
| -This is tested with ejabberd 14.12 and ubuntu server 14.04. |
| 52 | +Note that the scripts are pointing to Ejabberd version 16.08. If you're building against newer versions, you'll need to modify the paths in both `build.sh` and `Emakefile` regardless of whether you're on Mac OS X or not. |
0 commit comments