How to send WhatsApp notifications through Blip API Take Blip May 17, 2021 19:32 Updated 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 Business and Enterprise customers) Have a Message Template created and approved by WhatsApp After creating and approving your Message Template you will have access to two values NAMESPACE and ELEMENT_NAME. These values identify your Message Template and will be needed during the process. Have balance available in your account for triggering notifications on WhatsApp (consult your plan support team to review the balance available in your account) 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. #1 Request: 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. See an example of a number considering the country identifier equal to 55 (Brazil) and the DDD equal to 31 (Minas Gerais) +5531999998888 POST https://http.msging.net/commands HTTP/1.1 Content-Type: application/json Authorization: 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. #2 Request: 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://http.msging.net/messages HTTP/1.1 Content-Type: application/json Authorization: Key YOUR_TOKEN { "id":"{{RANDOM_ID}}", "to":"553175713755@wa.gw.msging.net", "type":"application/json", "content":{ "type":"template", "template":{ "namespace":"{{NAMESPACE}}", "name":"{{MESSAGE_TEMPLATE_NAME}}", "language":{ "code":"pt_BR", "policy":"deterministic" }, "components":[ { "type": "body", "parameters": [ { "type": "text", "text": "parâmetro1" }, { "type":"text", "text":"parâmetro2" } ] } ] } }} #3 Request: 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://http.msging.net/messages HTTP/1.1 Content-Type: application/json Authorization: Key YOUR_TOKEN { "id":"{{RANDOM_ID}}", "to":"553199998888@wa.gw.msging.net", "type":"application/json", "content":{ "type":"template", "template":{ "namespace":"{{NAMESPACE}}", "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":[ ] } ] } }} #4 Request: 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 or http://youtu.be/WU9gzjhyrcc, are not accepted. POST https://http.msging.net/messages HTTP/1.1 Content-Type: application/json Authorization: Key YOUR_TOKEN { "id":"{{RANDOM_ID}}", "to":"553199998888@wa.gw.msging.net", "type":"application/json", "content":{ "type":"template", "template":{ "namespace":"{{NAMESPACE}}", "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 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://http.msging.net/messages HTTP/1.1 Content-Type: application/json Authorization: Key YOUR_TOKEN { "id":"{{RANDOM_ID}}", "to":"553199998888@wa.gw.msging.net", "type":"application/json", "content":{ "type":"template", "template":{ "namespace":"{{NAMESPACE}}", "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" } ] } ] } }} #6 Request: 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://http.msging.net/messages HTTP/1.1 Content-Type: application/json Authorization: Key YOUR_TOKEN { "id":"{{RANDOM_ID}}", "to":"553175713755@wa.gw.msging.net", "type":"application/json", "content":{ "type":"template", "template":{ "namespace":"{{NAMESPACE}}", "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 NAMESPACE and 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. Related articles How to create and approve a Message Template on WhatsApp How to send notifications through Blip Desk ready responses How to configure service hours How to save a contact's WhatsApp number How to create a human service solution on WhatsApp