-
Notifications
You must be signed in to change notification settings - Fork 0
Whatsapp notifications
jannisvisser edited this page Mar 31, 2025
·
4 revisions
IBF allows to send WhatsApp notifications
- for trigger/warning alerts, so equivalent to email notifications
- for new community notifications (see guide on community notfications)
have a
community_notificationslayer which can be filled via a specific Kobo-form. The Kobo instances used by 510's IBF-system can be found in the internal Tech Doc. This guide allows how to set this up and work with it.
- Twilio setup
- Test sending WhatsApp message from local API with Twilio WhatsApp sandbox
- Test sending WhatsApp message from test/demo API with Twilio WhatsApp sandbox
IBF uses Twilio for sending WhatsApp messages.
- Set up Twilio
IBF-platformaccount - Create a
messaging service - Create
message templatesof which the text aligns withnotification-info.json, and copy the rightcontentSids. - In local .env update from that messaging service
TWILIO_SIDTWILIO_AUTHTOKENTWILIO_MESSAGING_SID
- and update
TWILIO_WHATSAPP_NUMBER= +14155238886 (the standard Twilio whatsapp sandbox number)
- Set up
ngrokto facilitate incoming messages. Since the initial WhatsApp message can be a validated template only, it cannot contain much specifics. Therefore it contains basic info and an invitation to reply 'yes'. Upon that 'yes' a 2nd message with more details is sent. (NOTE: this is only needed for trigger/warning notifications, not for community notifications, which do not come with incoming messages.)- Use ngrok to mock an external API service:
- Sign up on ngrok using your GitHub account
- Download the executable
- Add the folder to the system environment variables
- Add the
authtokenusing the command provided in the download page,ngrok config add-authtoken <token> - Run
ngrokon port 3000,ngrok http 3000 - You can find the URL of your API in the
Forwardingfield. Copy this:- As value for the
EXTERNAL_API_SERVICE_URLfield in the.envfile in the root folder - In the
WhatsApp sandbox settings(go to right subaccount > Develop > Messaging > Settings > Whatsapp sandbox settings) as:-
<EXTERNAL_API_SERVICE_URL>/api/notifications/whatsapp/incomingin theWHEN A MESSAGE COMES INfield -
<EXTERNAL_API_SERVICE_URL>/api/notifications/whatsapp/statusin theSTATUS CALLBACK URLfield
-
- As value for the
- Rebuild the service with
docker compose -d up ibf-api-service
Note
do not forget to put WhatsApp sandbox settings value back to its original value if you're using this same Twilio subaccount e.g. both for local testing and for remote test/demo environments
- Add your WhatsApp phone number to the WhatsApp sandbox by texting the code provided in the subaccount to the sandbox phone number as found in Twilio
- Create a new IBF-user through API with your WhatsApp phone number and assigned to the country and disaster-type you are testing for
- Send a whatsapp
- for a trigger/warning notification (for a country/disasterType with an active trigger) via the
POST /api/notification/sendendpoint. - for a community notification via the
POST /api/point-data/community-notificationendpoint
- for a trigger/warning notification (for a country/disasterType with an active trigger) via the
- You should receive the initial message. And upon a reply you should receive the follow-up message. Note that the initial message will arrive anyway, also if you did not set the above callback URLs correctly.
-
Ngrok is not needed, instead the
EXTERNAL_API_SERVICE_URLis simply the server URL itself, e.g.https://ibf-test.510.global/. -
Set the Twilio callback URLs to the right environment (ibf-test or ibf-demo). If e.g. ibf-test, that would be:
- In the
WhatsApp sandbox settings(go to right subaccount > Develop > Messaging > Settings > Whatsapp sandbox settings) -
https://ibf-test.510.global/api/notifications/whatsapp/incomingin theWHEN A MESSAGE COMES INfield -
https://ibf-test.510.global/api/notifications/whatsapp/statusin theSTATUS CALLBACK URLfield
- In the
For the rest, follow the same instructions as above to receive initial and follow-up messages.