Skip to content

Commit df02c96

Browse files
kzemekfenek
authored andcommitted
Add mod_event_pusher - frontend module for sns and push. (#1414)
* Add mod_event_pusher - frontend module for sns and push. * Add headline, normal messages to event_pusher events. * Put mod_http_notification under mod_event_pusher umbrella. * Fix style-related errors. * Compress hook declarations in mod_evenet_pusher_hook_translator. * Fix local includes not to use include_lib with incorrect path. * Update iq_handler arity of mod_event_pusher_push. * Fix mod_event_pusher_http_notifications to ignore unknown events. * Rename new push modules for better consistency. * Fix link in event pusher-related docs. * Redirect references to mod_{aws_sns,http_notification,push} to mod_event_pusher. * Fix mod_event_pusher_push types. * Implement suggested documentation improvements. * Get rid of documentation for deprecated push modules. For anyone still using them, the correct documentation will be pointed out in startup warnings. * Update Push tutorial image with new names
1 parent ca39886 commit df02c96

37 files changed

+1201
-911
lines changed

doc/advanced-configuration/Modules.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ A module used by SASL X-OAUTH mechanism.
3232
It provides an API to manage [custom OAuth tokens](../open-extensions/token-reconnection.md).
3333
It requires [mod_keystore](../modules/mod_keystore.md) as an actual key database.
3434

35-
### [mod_aws_sns](../modules/mod_aws_sns.md)
36-
Allows sending online/offline notifications, chat and groupchat messages as events to [Amazon Simple Notification Service](https://aws.amazon.com/sns/).
37-
3835
### [mod_blocking](../modules/mod_blocking.md)
3936
Implements [XEP-0191: Blocking Command](http://xmpp.org/extensions/xep-0191.html), a simplified interface to privacy lists.
4037

@@ -59,7 +56,16 @@ Enables the [XEP-0352: Client State Indication](http://xmpp.org/extensions/xep-0
5956
### [mod_disco](../modules/mod_disco.md)
6057
Implements [XEP-0030: Service Discovery](http://xmpp.org/extensions/xep-0030.html) for discovering information (capabilities, protocols, features) about other XMPP entities.
6158

62-
### [mod_http_notification](../modules/mod_http_notification.md)
59+
### [mod_event_pusher](../modules/mod_event_pusher.md)
60+
A framework module to build other notification-based modules on.
61+
62+
#### [mod_event_pusher_sns](../modules/mod_event_pusher_sns.md)
63+
Allows sending online/offline notifications, chat and groupchat messages as events to [Amazon Simple Notification Service](https://aws.amazon.com/sns/).
64+
65+
#### [mod_event_pusher_push](../modules/mod_event_pusher_push.md)
66+
Implements [XEP-0357 Push Notifiactions](https://xmpp.org/extensions/xep-0357.html) to provide push notifications to clients that are temporary unavailable.
67+
68+
#### [mod_event_pusher_http](../modules/mod_event_pusher_http.md)
6369
Forward events to an external HTTP service.
6470
This applies to situations such as sending messages or presences to mobile/SMS/email push service, big data, or an analytics service.
6571

@@ -109,9 +115,6 @@ Implements [XEP-0049 (Private XML Storage)](http://xmpp.org/extensions/xep-0049.
109115
### [mod_pubsub](../modules/mod_pubsub.md)
110116
This extension implements [XEP-0060 (Publish-Subscribe)](http://www.xmpp.org/extensions/xep-0060.html). It is a pluggable implementation using behaviours provided by `node_*.erl` and `nodetree_*.erl` modules.
111117

112-
### [mod_push](../modules/mod_push.md)
113-
Implements [XEP-0357 Push Notifiactions](https://xmpp.org/extensions/xep-0357.html) to provide push notifications to clients that are temporary unavailable.
114-
115118
### [mod_push_service_mongoosepush](../modules/mod_push_service_mongoosepush.md)
116119
Handles push notifications generated by [mod_pubsub](../modules/mod_pubsub.md)'s `node_push` and passes them to [MongoosePush](https://github.com/esl/MongoosePush) service.
117120

@@ -143,4 +146,3 @@ Provides support for vCards, as specified in [XEP-0054: vcard-temp](http://xmpp.
143146

144147
### [mod_version](../modules/mod_version.md)
145148
This module provides the functionality specified in [XEP-0092: Software Version](https://xmpp.org/extensions/xep-0092.html).
146-

doc/developers-guide/hooks_description.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Selected hooks description
22

3-
This is a brief documentation for a few selected hooks.
4-
Though hooks & handlers differ in what they are there to do, it is not necessary to describe them all, because the mechanism is general.
3+
This is a brief documentation for a few selected hooks.
4+
Though hooks & handlers differ in what they are there to do, it is not necessary to describe them all, because the mechanism is general.
55
The following is meant to give you the idea of how hooks work, what they are used for and the various purposes they can serve.
66

77

@@ -19,7 +19,7 @@ Some rudimentary verification of the stanza is done once it is received from the
1919
if the identity does not match the contents of the attribute, an error is returned,
2020
- the recipient JID (`to` attribute) format is verified.
2121

22-
The hook is not run for stanzas which do not pass these basic validity checks.
22+
The hook is not run for stanzas which do not pass these basic validity checks.
2323
Neither are such stanzas further processed by the server.
2424

2525
This hook won't be called for stanzas arriving from a user served by a federated server (i.e. on a server-to-server connection handled by `ejabberd_s2s`) intended for a user served by the relevant ejabberd instance.
@@ -30,7 +30,7 @@ It is handled by the following modules:
3030

3131
* `mod_carboncopy` - if the packet being sent is a message, it forwards it to all the user's resources which have carbon copying enabled
3232

33-
* `mod_http_notification` - if configured, sends selected messages to an external http service
33+
* `mod_event_pusher_http` - if configured, sends selected messages to an external http service
3434

3535
* `mod_mam` - stores outgoing messages in an archive
3636

@@ -66,7 +66,7 @@ ejabberd_hooks:run_fold(filter_packet,
6666
{OrigFrom, OrigTo, OrigPacket}, [])
6767
```
6868

69-
This hook is run by `mongoose_router_global` when the packet is being routed by `ejaberd_router:route/3`.
69+
This hook is run by `mongoose_router_global` when the packet is being routed by `ejaberd_router:route/3`.
7070
It is in fact the first call made within the routing procedure.
7171
If a function hooked in to `filter_packet` returns `drop`, the packet is not processed.
7272

@@ -91,11 +91,11 @@ ejabberd_hooks:run(offline_message_hook,
9191

9292
`ejabberd_sm` runs this hook once it determines that a routed stanza is a message and while it ordinarily could be delivered, no resource (i.e. device or desktop client application) of its recipient is available online for delivery.
9393

94-
The hook is first handled by `mod_offline`, which should store that message in a persistent way until the recipient comes online and the message can be successfully delivered.
94+
The hook is first handled by `mod_offline`, which should store that message in a persistent way until the recipient comes online and the message can be successfully delivered.
9595
The handler in `mod_offline` stores the message and returns `stop`, which terminates the call and no more hook handlers are called.
9696

97-
If the `mod_offline` handler fails to store the message, we should notify the user that the message could not be stored.
98-
To this end, there is another handler registered, but with a greater sequence number, so that it is called after `mod_offline`.
97+
If the `mod_offline` handler fails to store the message, we should notify the user that the message could not be stored.
98+
To this end, there is another handler registered, but with a greater sequence number, so that it is called after `mod_offline`.
9999
If `mod_offline` fails, `ejabberd_sm:bounce_offline_message` is called and the user gets their notification.
100100

101101
## `remove_user`
@@ -104,7 +104,7 @@ If `mod_offline` fails, `ejabberd_sm:bounce_offline_message` is called and the u
104104
ejabberd_hooks:run(remove_user, Server, [User, Server])
105105
```
106106

107-
`remove_user` is run by `ejabberd_auth` - the authentication module - when a request is made to remove the user from the database of the server.
107+
`remove_user` is run by `ejabberd_auth` - the authentication module - when a request is made to remove the user from the database of the server.
108108
This one is rather complex, since removing a user requires many cleanup operations:
109109
`mod_last` removes last activity information (xep 0012);
110110
`mod_mam` removes the user's message archive;
@@ -121,14 +121,14 @@ and `mod_roster` removes the user's roster from database.
121121
ejabberd_hooks:run(node_cleanup, [Node])
122122
```
123123

124-
`node_cleanup` is run by a mongooseim_cleaner process which subscribes to `nodedown` messages.
124+
`node_cleanup` is run by a mongooseim_cleaner process which subscribes to `nodedown` messages.
125125
Currently the hook is run inside a global transaction (via `global:trans/4`).
126126

127-
The job of this hook is to remove all processes registered in Mnesia.
128-
MongooseIM uses Mnesia to store processes through which messages are then routed - like user sessions or server-to-server communication channels - or various handlers, e.g. IQ request handlers.
127+
The job of this hook is to remove all processes registered in Mnesia.
128+
MongooseIM uses Mnesia to store processes through which messages are then routed - like user sessions or server-to-server communication channels - or various handlers, e.g. IQ request handlers.
129129
Those must obviously be removed when a node goes down, and to do this the modules `ejabberd_local`, `ejabberd_s2s`, `ejabberd_sm` and `mod_bosh` register their handlers with this hook.
130130

131-
Number of retries for this transaction is set to 1 which means that in some situations the hook may be run on more than one node in the cluster, especially when there is little garbage to clean after the dead node.
131+
Number of retries for this transaction is set to 1 which means that in some situations the hook may be run on more than one node in the cluster, especially when there is little garbage to clean after the dead node.
132132
Setting retries to 0 is not good decision as it was observed that in some setups it may abort the transaction on all nodes.
133133

134134
## `session_opening_allowed_for_user`
@@ -145,7 +145,7 @@ Handler function are expected to return:
145145
* `deny` if the JID is not allowed but other handlers should be run
146146
* `{stop, deny}` if the JID is not allowed but other handlers should **not** be run
147147

148-
In the default implementation the hook is not used, built-in user control methods are supported elsewhere.
148+
In the default implementation the hook is not used, built-in user control methods are supported elsewhere.
149149
This is the perfect place to plug in custom security control.
150150

151151
## other hooks

doc/developers-guide/mod_muc_light_developers_guide.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Hooks executed by this extension
9696

9797
* `filter_room_packet` by codecs - Allows `mod_mam_muc` to archive groupchat messages.
9898

99-
* `room_send_packet` by codecs - Handled by `mod_aws_sns`.
99+
* `room_send_packet` by codecs - Handled by `mod_event_pusher_sns`.
100100

101101
* `forget_room` by `mod_muc_light_db_mnesia` and `mod_muc_light_room` - It is a part of `mod_mam_muc` integration as well.
102102
A hook used for MAM cleanup upon room destruction.
@@ -144,4 +144,3 @@ Ideas for Further Development
144144
### Hard
145145

146146
* Room metadata cache (maybe "medium"?).
147-

doc/modules/mod_event_pusher.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
### Module Description
2+
This module is a generic interface for event pushing backends.
3+
It defines a single hook, `push_event/3` that forwards the event to all registered backends.
4+
Each backend decides how and if to handle the event in its `push_event/2` implementation.
5+
6+
The events are standardized as records that can be found in `mod_event_pusher_events.hrl` file.
7+
Common events like user presence changes (offline and online), chat and groupchat messages (incoming and outgoing) are already hooked up to the frontend via `mod_event_pusher_hook_translator` which is a proxy between various hooks and `push_event/3` hook handler.
8+
9+
### Options
10+
11+
* **backends** (required, list) - Specifies backends to register with the frontend, along with arguments that will be passed to the backend.
12+
Currently supported backends include [sns], [push] and [http_notification].
13+
Refer to their specific documentation to learn more about their functions and configuration options.
14+
15+
### Example configuration
16+
17+
```Erlang
18+
{mod_event_pusher, [
19+
{backends, [
20+
{sns, [
21+
{access_key_id, "AKIAIOSFODNN7EXAMPLE"},
22+
{secret_access_key, "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"},
23+
% ...
24+
]},
25+
{push, [
26+
{backend, mnesia},
27+
{wpool, [{workers, 200}]},
28+
{plugin_module, mod_event_pusher_push_plugin_defaults}
29+
]}
30+
]}
31+
]}
32+
```
33+
34+
[sns]: ./mod_event_pusher_sns.md
35+
[push]: ./mod_event_pusher_push.md
36+
[http_notification]: ./mod_event_pusher_http.md
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
## Module description
22

3-
This module enables forwarding certain events (messages, presence, etc.) via HTTP to external services such as push (by mobile, email or SMS), big data, or analytics services.
3+
This module is a backend of [mod_event_pusher] that enables forwarding certain events (messages, presence, etc.) via HTTP to external services such as push (by mobile, email or SMS), big data, or analytics services.
44

55
### How it works
66

7-
The module adds a handler to a `user_send_packet` hook which is triggered every time a user sends anything.
7+
The module hooks on all packets sent by connected users.
88
When the hook is triggered, the module:
99

10-
* checks whether http_notification is enabled (the `host` param is set)
1110
* runs a callback module's `should_make_req/3` function to see if a notification should be sent
1211
* sends a POST request composed of `{Host::binary(), Sender::binary(), Receiver::binary(), Message::binary()}` to the http notification server
1312

1413
### Callback module
1514

1615
To find out what should be sent to the HTTP server, MongooseIM calls `Mod:should_make_req(Packet::xmlel(), From::jid(), To::jid())`.
17-
By default it uses the function in mod_http_notification itself, which ships all non-empty chat messages and nothing else. The module can be substituted here, the method should return `true | false`.
16+
By default it uses the function in `mod_event_pusher_http` itself, which ships all non-empty chat messages and nothing else. The module can be substituted here, the method should return `true | false`.
1817

1918
## Prerequisites
2019

21-
This module uses a connection pool created by mongoose_http_client. It must be defined in `http_connections` settings.
20+
This module uses a connection pool created by mongoose_http_client. It must be defined in the `http_connections` settings.
2221

2322
## Options
2423

@@ -32,17 +31,29 @@ This module uses a connection pool created by mongoose_http_client. It must be d
3231
{pool_size, 50}, {path_prefix, "/webservice"}]}
3332
]}.`
3433

35-
`{mod_http_notification, [{pool_name, http_pool}, {path, "/notifications"}]}`
34+
```erlang
35+
{mod_event_pusher, [
36+
{backends, [
37+
{http, [
38+
{pool_name, http_pool},
39+
{path, "/notifications"}
40+
]}
41+
]}
42+
]}
43+
```
3644

3745
Notifications will be POSTed to `http://localhost:8000/webservice/notifications`.
3846

3947
## Metrics
4048

41-
If you'd like to learn more about metrics in MongooseIM, please visit [MongooseIM metrics](../operation-and-maintenance/Mongoose-metrics.md) page.
49+
If you'd like to learn more about metrics in MongooseIM, please visit [MongooseIM metrics](../operation-and-maintenance/Mongoose-metrics.md** page.
50+
51+
> **Warning:** the metrics' names may change once the deprecated `mod_http_notification` is removed from MongooseIM.
4252
4353
| Name | Type | Description (when it gets incremented) |
4454
| ---- | ---- | -------------------------------------- |
4555
| `[Host, mod_http_notifications, sent]` | spiral | An HTTP notification is sent successfully. |
4656
| `[Host, mod_http_notifications, failed]` | spiral | An HTTP notification failed. |
4757
| `[Host, mod_http_notifications, response_time]` | histogram | Does not include timings of failed requests. |
4858

59+
[mod_event_pusher]: ./mod_event_pusher.md
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
### Module Description
2+
3+
This module is a backend of [mod_event_pusher] that implements [XEP-0357: Push Notifications](https://xmpp.org/extensions/xep-0357.html).
4+
It enables a service that notifies `PubSub` of a user's choice about every message that they could miss while being offline.
5+
There are two control stanzas that the client can send to this module: `enable` and `disable`.
6+
The `enable` stanza enables push notifications and forwards them to a specified `PubSub` node.
7+
This stanza may also contain an optional `Data Form` that will be added to each and every notification to `PubSub` node as `publish-options`.
8+
Please be sure to provide all form fields required by the specified `PubSub` node.
9+
Any publish error may result in disabling push notifications to this node.
10+
11+
### Options
12+
13+
* **backend** (atom, default: `mnesia`) - Backend to use for storing the registrations.
14+
Currently only `mnesia` may be used.
15+
* **wpool** (list, default: `[]`) - List of options that will be passed to the `worker_pool` library that handles all the requests.
16+
Please refer to the [Project Site](https://github.com/inaka/worker_pool) for more details.
17+
* **plugin_module** (atom, default: `mod_event_pusher_push_plugin_defaults`) - module implementing `mod_event_pusher_push_plugin` behaviour,
18+
used for dynamic configuration of push notifications. Read more about it [here](#plugin-module)
19+
20+
### Plugin module
21+
22+
A plugin module handles dynamic configuration of push notifications. It implements `mod_event_pusher_push_plugin` behaviour which
23+
requires two callbacks:
24+
25+
* `should_publish/3` - callback used for filtering push notifications. A push notification is triggered for given a message only if this
26+
callback returns `true`.
27+
28+
```
29+
-spec should_publish(From :: ejabberd:jid(), To :: ejabberd:jid(), Packet :: jlib:xmlel()) -> boolean().
30+
```
31+
32+
* `sender_id/2` - allows modifying `last-message-sender` field, which ultimately becomes a `title` of the delivered push notification.
33+
34+
```
35+
-spec sender_id(From :: ejabberd:jid(), Packet :: jlib:xmlel()) -> SenderId :: binary().
36+
```
37+
38+
### Example configuration
39+
40+
```Erlang
41+
{mod_event_pusher, [
42+
{backends, [
43+
{push, [
44+
{backend, mnesia},
45+
{wpool, [{workers, 200}]},
46+
{plugin_module, mod_event_pusher_push_plugin_default}
47+
]}
48+
]}
49+
]}
50+
```
51+
52+
[mod_event_pusher]: ./mod_event_pusher.md

0 commit comments

Comments
 (0)