Ejabberd 17: How to create a hook which is called for offline messages?

379 views Asked by At

I want to create a hook which is called whenever an offline message is created. Example: user-a(online) send a message to user-b(offline). Then as per ejabberd the message is stored and sent when user-b comes online. But in this situation, I want to call a local server POST URL with the data. How to create such a hook?

This hook is created so that I can from the local server send a push notification. Thus whenever a user comes online he/she will get the offline message as the push notification.

There is no step by step implementation for this. If anyone knows this it will be of great help.

2

There are 2 answers

0
Badlop On

There are two hooks called when a message is sent to a local account that is offline: ejabberd_sm calls offline_message_hook. And mod_offline calls store_offline_message. Search for that in the ejabberd source code, and you will find example code to use them.

0
MMujtabaRoohani On

Building on Badlop's answer, I have created a module that does exactly what you need to achieve from an offline_hook. Only with a difference that you'll have to connect a component to ejabberd instead of getting messages on REST API.