How to send WhatsApp notifications through Blip API February 14, 2024 18:42 Updated Index: Introduction Sending a notification Request 1: Fetching a customer's identifier Request 2: Send notification with text only Request 3: Sending notification with image Request 4: Sending notification with video Request 5: Sending the notification with document Request 6: Sending the notification with quick reply Note: Address for a registered subbot as a router service Introduction Through Blip, it is possible to create applications for the WhatsApp channel capable of not only responding to incoming messages, but also of actively sending messages (notifications) to the customer. Any message sent by the bot, after a period of 24 hours in relation to the last message sent by the client is considered a notification. To learn more about the differences between a normal message and a notification click here. Notifications on WhatsApp are always associated with a Message Template, previously approved by WhatsApp itself. To send a notification (active message) it is necessary to ensure that the prerequisites below have already been satisfied: Have a bot previously published on the WhatsApp channel (only available to customers with a paid plan) Have a Message Template created and approved by WhatsApp After creating and approving your Message Template and you will have access to a value NAME (Template name). These values identify your Message Template and will be needed during the process. Sending a notification To send a notification via the Blip API, you will need to make 2 HTTP requests in the Blip API. The first one has the objective of searching for a customer's identifier in WhatsApp and should be executed only once for each user. The second request is responsible for effectively triggering a notification through a specific Message Template. Request 1: Fetching a customer's identifier Before sending a notification, you must have access to the user's identifier in WhatsApp. Remember to perform this operation only once for each customer. The search for the identifier is done through an HTTP request taking into account the customer's cell phone number in international format. “+ DDI DDD PHONE_NUMBER”. ATTENTION POINT: Do not forget to add the "+" (plus) sign before submitting. More details on user verification, check contact and the validity of the consulted number, access here. See an example of a number considering the country identifier equal to 55 (Brazil) and the DDD equal to 31 (Minas Gerais) +5531999998888 Note: Use the url with the contract id to consume the endpoints reported below, its performance and operation may be impacted if it does not have the contract id, so it is essential to use the url with the contract id to use http requests! POST https://http.msging.net/commands HTTP/1.1Content-Type: application/jsonAuthorization: Key YOUR_TOKEN { "id": "a456-42665544000-0123e4567-e89b-12d3", "to": "postmaster@wa.gw.msging.net", "method": "get", "uri": "lime://wa.gw.msging.net/accounts/+5531999998888"} Note that one of the headers in this request requires a bot authorization token (YOUR_TOKEN). Below is an example of a response to this request. Note that the resource property has a JSON object that contains the alternativeAccount property, this is the value that identifies the customer on the WhatsApp channel. 5531999998888@wa.gw.msging.net - identifier of the customer who has the mobile number 5531999998888 { "type": "application/vnd.lime.account+json", "resource": { "fullName": "John Doe", "alternativeAccount": "5531999998888@wa.gw.msging.net", "identity": "5531999998888@wa.gw.msging.net", "phoneNumber": "+5531999998888", "source": "WhatsApp" }, "method": "get", "status": "success", "id": "a456-42665544000-0123e4567-e89b-12d3", "from": "postmaster@wa.gw.msging.net", "to": "bot@msging.net", "metadata": { "#command.uri": "lime://wa.gw.msging.net/accounts/+5531999998888" }} Note: This operation must be performed only once for each customer. Request 2: Send notification with text only In possession of the identifier of the client that will receive the notification, perform the HTTP request described below by changing its id: POST https://{{contractid}}.http.msging.net/messages HTTP/1.1 Content-Type: application/json Authorization: Key YOUR_TOKEN { "id":"{{$guid}}", "to":"553175713755@wa.gw.msging.net", "type":"application/json", "content":{ "type":"template", "template":{ "name":"{{MESSAGE_TEMPLATE_NAME}}", "language":{ "code":"pt_BR", "policy":"deterministic" }, "components":[ { "type": "body", "parameters": [ { "type": "text", "text": "parâmetro1" }, { "type":"text", "text":"parâmetro2" } ] } ] } }} (The sending code above, shows an example of a Template with 2 text variables in the object parameters) Request 3: Sending notification with image In possession of the identifier of the client that will receive the notification, perform the HTTP request described below by changing its id: POST https://{{contractid}}.http.msging.net/messages HTTP/1.1 Content-Type: application/json Authorization: Key YOUR_TOKEN { "id":"{{$guid}}", "to":"553199998888@wa.gw.msging.net", "type":"application/json", "content":{ "type":"template", "template":{ "name":"{{MESSAGE_TEMPLATE_NAME}}", "language":{ "code":"pt_BR", "policy":"deterministic" }, "components":[ { "type":"header", "parameters":[ { "type":"image", "image":{ "link":"https://www.Blip.ai/wp-content/uploads/2018/02/logo-Blip.png" } } ] }, { "type":"body", "parameters":[ ] } ] } }} Request 4: Sending notification with video In possession of the identifier of the client that will receive the notification, perform the HTTP request described below by changing its id: The video size must be a maximum of 16MB. YouTube links, such as: https://www.youtube.com/watch?v=WU9gzjhyrcc http://youtu.be/WU9gzjhyrcc, are not accepted. POST https://{{contractid}}.http.msging.net/messages HTTP/1.1 Content-Type: application/json Authorization: Key YOUR_TOKEN { "id":"{{$guid}}", "to":"553199998888@wa.gw.msging.net", "type":"application/json", "content":{ "type":"template", "template":{ "name":"{{MESSAGE_TEMPLATE_NAME}}", "language":{ "code":"pt_BR", "policy":"deterministic" }, "components":[ { "type":"header", "parameters":[ { "type":"video", "video":{ "link":"http://techslides.com/demos/sample-videos/small.mp4" } } ] }, { "type":"body", "parameters":[ ] } ] } }}#5 Request: Sending notification with document Request 5: Sending the notification with document In possession of the identifier of the client that will receive the notification, perform the HTTP request described below by changing its id: POST https://{{contractid}}.http.msging.net/messages HTTP/1.1 Content-Type: application/json Authorization: Key YOUR_TOKEN { "id":"{{$guid}}", "to":"553199998888@wa.gw.msging.net", "type":"application/json", "content":{ "type":"template", "template":{ "name":"{{MESSAGE_TEMPLATE_NAME}}", "language":{ "code":"pt_BR", "policy":"deterministic" }, "components":[ { "type":"header", "parameters":[ { "type":"document", "document":{ "filename":"take.pdf", "link":"http://www.orimi.com/pdf-test.pdf" } } ] }, { "type":"body", "parameters":[ { "type":"text", "text":"Blip" } ] } ] } }} Request 6: Sending the notification with quick reply In possession of the identifier of the client that will receive the notification, perform the HTTP request described below by changing its id: POST https://{{contractid}}.http.msging.net/messages HTTP/1.1 Content-Type: application/json Authorization: Key YOUR_TOKEN { "id":"{{$guid}}", "to":"553175713755@wa.gw.msging.net", "type":"application/json", "content":{ "type":"template", "template":{ "name":"{{MESSAGE_TEMPLATE_NAME}}", "language":{ "code":"pt_BR", "policy":"deterministic" }, "components":[ { "type": "body", "parameters": [ { "type": "text", "text": "Any message. Would you like to reply?" } ] }, { "type": "button", "sub_type": "quick_reply", "index": 0, "parameters": [ { "type": "payload", "payload": "Sim" } ] }, { "type": "button", "sub_type": "quick_reply", "index": 1, "parameters": [ { "type": "payload", "payload": "Yes" } ] } ] } }} Note that in addition to the bot token and the customer identifier, it will be necessary to change the MESSAGE_TEMPLATE_NAME values in the request body corresponding to the pre-approved Message Template. In addition, it is necessary to insert the values of the variables defined in the creation of the Message Template, when applicable. Note: Address for a registered subbot as a router service Important: For this process to work properly, in the flow settings, the Use Router context option must be turned on in all router subbots (services). To direct a user to a subbot registered as a router service, after sending an active message via API, it is necessary to execute the Master state request to identify it. Master state: POST https://http.msging.net/commands HTTP/1.1Content-Type: application/jsonAuthorization: Key {YOUR_ROUTER_TOKEN} {"id": "{{$guid}}","to": "postmaster@msging.net","method": "set","uri": "/contexts/{{contact.identity}}/Master-State","type": "text/plain","resource": "{{idDoSubbot}}@msging.net"} If you want to target a specific block of the bot, it is necessary to execute the change user state request, using the same contact.identity and the same router authorization key. Change user state: POST https://http.msging.net/commands HTTP/1.1Content-Type: application/jsonAuthorization: Key {YOUR_ROUTER_TOKEN} { "id": "{{$guid}}", "to": "postmaster@msging.net", "method": "set", "uri": "/contexts/{{contact.identity}}/stateid@{{flow-identifier}}", "type": "text/plain", "resource": "{{state-id}}"} It is worth mentioning that the block to which the user will be directed will not display its content, performing only the exit conditions and actions, which will be validated after the user's response. For this reason, it is advisable to keep a user input button (user input) in the block where the user's message will be received and without content (messages). Then create an output condition to handle his response and direct it to the desired block. e.g.: For more information, visit the discussion on the subject in our community or the videos on our channel. 😃 Related articles How to Send Notifications via the Active Campaign API (Growth) WhatsApp channel update - Check Contact Sending WhatsApp Active Messages on Blip Desk Creating interactive messages in WhatsApp Audience file configuration - Bulk notification sending