Mediator: Communication
This service centralizes all communications and sending of messages and notifications in a single point.Ā
Since there are several providers-aggregators that have different APIS and requests, this service has been created to communicate with them in a simple and agile way.Ā
This service also focuses on how you want to communicate, for different countries and projects, so this information is vital to be able to select the desired type of communication without having to specify the provider. When there are several projects, it is difficult to remember which communication method was used for them.
Here's why:
Since each provider has different APIs AND endpoints, having one service that manages all of them is a very convenient solution to manage.
Having this service avoids adding more complexity to other services that require sending a message or a notification to a user.
It has been designed to be able to work with openHim and to be able to have this service linked.Ā
Ā
This is an example of a payload to send the message:
{
"project": "{{projectID}}",
"msg": "Hi, I'm a test",
"channel": "{{channel}}",
"to": "{{to}}",
"from": "{{from}}"
}
Ā
msgType: Different providers allow us to send different message types (text, images, sound, templatesā¦). Most of the projects use Meta and have their own API. We try to use the same types as Meta to avoid misspellings and mistakes.
Our current message types are: image | template | text | quick-replies. ātextā is the default type.
Example to send WhatsApp message with quick replies (previously, you need to start the conversation):
Ā
{
"project": "{{project}}",
"msg": "More info: https://developers.facebook.com/docs/whatsapp/cloud-api/messages/interactive-reply-buttons-messages/",
"channel": "whatsapp",
"to": "{{phone}}",
"lang": "en",
"msgType": "quick-replies",
"extraParams": {
"header": {
"type": "text",
"text": "You can remove this. This is a mega title"
},
"action": {
"buttons": [
{
"type": "reply",
"reply": {
"id": "sad",
"title": "Sad"
}
},
{
"type": "reply",
"reply": {
"id": "happy",
"title": "Fine"
}
}
]
},
"footer": "You can remove this if you are not using it."
}
}
the client will see:
Ā
Ā
This is an example to send an image:
{
"project": "TEST-FB",
"msgType": "image",
"msg": "https://www.psi.or.tz/images/logo_psi.png",
"channel": "facebook",
"to": "{{fb-psid}}",
}
ā ļø Before starting to use this service in a project, you need to communicate with the service admin to update the configuration.
For each project, the service needs a configuration (which channels are going to use the project, which aggregators exist, and credentials). After that, we can use it easily to send POST requests with the previous payload template.
You can find more examples in this POSTMAN workspace: POSTMAN
You can find the service repository here: GITHUB REPOSITORY
Ā
If you have any doubt, you can contact ghernandez@psi.org