WhatsApp APIs

WhatsApp APIs

Send WhatsApp Template Message

WhatsApp provides their own templated message mechanism. Message templates are plain text messages that are individually approved by the WhatsApp team to ensure they do not violate the WhatsApp policies. Businesses must use templated messages when first reaching out to users or when sending a message 24hours after the last message from the user. This type of message is paid.

Here’s an example:

"Your order {{1}} for a total of {{2}} is confirmed. The expected delivery is {{3}}."

Notice the {{1}} parameter that allows you to personalise the message being sent.

Giving parameter values in your post-session message:

If the Message Template of your post-session messages uses properties/parameters, you need to supply the values of those parameters when you are trying to send the template message.

To supply new values for your post-session params, you can use postSessionParams or customerData. If you do not include either of these, the existing values of those properties saved in the customer will be used.

Method POST

Header

Authorization: ACCESS TOKEN  
Content-Type: application/json

Body


{
    "customerData"       : {
    "PROPERTY_TITLE"     : "VALUE"
},
    "accountId": "ACCOUNT_ID",
    "templateId": "TEMPLATE_ID",
    "postSessionParams"  : ["PARAMETERS"]
}
Property
Description
Required
accountId
This is the ID of your ‘WhatsApp Account’. Request this id by sending an email on support@morph.ai
Y
templateId
This is the ID of the ‘Message Template’. This is available in the URL of each message template.


Y
customerData
This is a key value pair of properties you want to update in the customer. The customer data will be updated as per the given new values of the property. The post-session message is then sent out, intrinsically using the new value of the properties.
Note: The properties used in customerData should already exist on the system. You can check or create a new property here.
Optional
postSessionParams
This is an ordered list of all the param values, appearing in the order in which the params appear in the Message Template.
This has higher priority then customerData, hence these values will be used if both customerData and postSessionParams are included in the body. However, the customer object will be updated with the values in customerData.
Optional

Example

Request: 

curl -X POST \
  https://open-api.morph.ai/v1/customer/wa/create \  
  -H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlkIjoiNWNhYzc3ZmNlMWE3NTQ2ZWQwZGIyMmMzIn0.eyJzY29wZSI6ImFwaSJ9.9q2QpFpzOepSf4KQmUDVvHUo07BxFzYdsxL_cn8Wm3w' \
  -H 'Content-Type: application/json' \"
  -d '{
    "accountId": "5cee6ca1c551ecb1d9df4e05",
    "templateId": "5cfdf714930d64f74e365823",
    "postSessionParams"  : ["Test Name", "Test Email", "Temp Id"]
}'
Response:

{
    "status" : "success"
}


Send or receive message by your own

If you want to send or receive messages from your own platform without using Morph automation, you can do that by enabling the APIs. To enable the APIs, you can contact support.

Send and Receive details are as below:

Receive

This endpoint can be used to send messages to a particular WhatsApp user. Create an API which should accept calls in the below format. Register the APIs with Support. Whenever a message is received from the customer, it will automatically be passed to your platform.

Example payload that you'll receive

Header : application/json

Body

{
    "userId": "USER_ID",
    "widgetId": "WIDGET_ID",
    "messages": [
        {
            "type": "statement",
            "text": "Here is a sample response to user"
        }
    ]
}
            
Property
Description
Required
widgetId
The widget id representing the id of the deployed webhook integration.
Y
userId
Customer ID or user's phone number
Y


Send

This endpoint can be used to send messages to a particular WhatsApp user.

Request

URL: https://open-api.morph.ai/v1/message/send

MethodPOST

Header

Authorization: ACCESS TOKEN  
Content-Type: application/json
Body

{
    "userId": "USER_ID",
    "widgetId": "WIDGET_ID_HERE",
    "messages": [
        {
            "type": "statement",
            "text": "Here is a sample response to user"
        }
    ]
}
Property
Description
Required
userId
The user id of the user to whom you want to send the message to.
This is also received along with the message to the webhook.
Y
widgetId
The widget id representing the id of the deployed webhook integration.
Received along with the message to the webhook
Y
messages
An array containing message object
Y


Customer creation/update

If you want to create a user record or update his/her details without using Morph automation, you can do that by using the below APIs.

Create

Authorization: ACCESS TOKEN  
Content-Type: application/json
Body

{
    "customerData"       : {
    "PROPERTY_TITLE"     : "VALUE"
},
    "accountId"          : "ACCOUNT_ID",
    "postSessionParams"  : ["PARAMETERS"]
}
Property
Description
Required
accountId
This is the ID of your ‘WhatsApp Account’.Request this id by sending an email on support@morph.ai
Y
customerData
This is a key value pair of properties you want to update in the customer. The customer data will be updated as per the given new values of the property. The post-session message is then sent out, intrinsically using the new value of the properties.
Note: The properties used in customerData should already exist on the system. You can check or create a new property here.
Optional
postSessionParams
This is an ordered list of all the param values, appearing in the order in which the params appear in the Message Template.
This has higher priority then customerData, hence these values will be used if both customerData and postSessionParams are included in the body. However, the customer object will be updated with the values in customerData.
Optional

Example

Request:


curl -X POST \
  https://open-api.morph.ai/v1/customer/wa/create \  
  -H 'Authorization: <ACCESS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{
    "customerData": {
        "Phone Number": "+919876543210"
    },
    "accountId":"<ACCOUNT_ID>",
    "postSessionParams": ["Test Name", "Test Email", "Temp Id"]
}'
Response:

{
    "status": "success",
    "customer": {
        "createdTime": 1568113903575,
        "updatedTime": 1568113903575,
        "isDeleted": false,
        "bI": "morphaig84mnprv",
        "id": "5d7784ee278858527cbae2f9",
        "iOnbrdngDn": false,
        "interfaceAccounts": [
            {
                "isDeleted": false,
                "id": "656f0bda4dde6c2c949c3292",
                "iOnbrdngDn": false,
                "channel": "smooch_whatsapp",
                "key": "smooch_whatsapp___656f0bda4dde6c2c949c3292",
                "lstPSTm": 0
            }
        ],
        "iVPV": {
            "bl___isBlckd": false,
            "tx___lN": "",
            "cltx___bIAK": {
                "vs": [
                    "smooch_whatsapp___5ced1f6a44c59900103a6ced"
                ],
                "t": "Set"
            },
            "tx___nm": "User - g1FQW0",
            "pn___pN": "+919876543210",
            "bl___isRU": false,
            "tx___fN": "User - g1FQW0",
            "tm___lMT": 1568113903291,
            "bl___iAs": false
        }
    }
}

Update


Method PUT

Header

Authorization: ACCESS TOKEN  
Content-Type: application/json
Body

{
    "customerData"       : {
    "PROPERTY_TITLE"     : "VALUE"
},
    "accountId": "ACCOUNT_ID"
}
Property
Description
Required
accountId
This is the ID of your ‘WhatsApp Account’.Request this id by sending an email on support@morph.ai
Y
customerData
This is a key value pair of properties you want to update in the customer. The customer data will be updated as per the given new values of the property. The post-session message is then sent out, intrinsically using the new value of the properties.
Note: The properties used in customerData should already exist on the system. You can check or create a new property here.
Optional

Example

Request:

curl -X PUT \
  https://open-api.morph.ai/v1/customer/wa/create \  
  -H 'Authorization: <ACCESS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{
    "customerData" : {
    "First Name"   : "Vipul Test"
    },
    "accountId":"<ACCOUNT_ID>"
}'
Response:

{
    "status": "success",
    "customer": {
        "createdTime": 1568113903575,
        "updatedTime": 1568114021072,
        "isDeleted": false,
        "bI": "morphaig84mnprv",
        "id": "5d7784ee278858527cbae2f9",
        "iOnbrdngDn": false,
        "interfaceAccounts": [
            {
                "isDeleted": false,
                "id": "656f0bda4dde6c2c949c3292",
                "iOnbrdngDn": false,
                "channel": "smooch_whatsapp",
                "key": "smooch_whatsapp___656f0bda4dde6c2c949c3292",
                "lstPSTm": 0
            }
        ],
        "iVPV": {
            "bl___isBlckd": false,
            "tx___lN": "",
            "cltx___bIAK": {
                "vs": [
                    "smooch_whatsapp___5ced1f6a44c59900103a6ced"
                ],
                "t": "Set"
            },
            "tx___nm": "User - g1FQW0",
            "pn___pN": "+919876543210",
            "bl___isRU": false,
            "tx___fN": "Vipul Test",
            "tm___lMT": 1568113903291,
            "bl___iAs": false
        }
    }
}


    • Related Articles

    • [WhatsApp] How to build WhatsApp chatbot

      Morph.ai is a chat based intelligent automation tool that helps business to interact with their customers directly. It is an integrated set of modules and analytics that help you manage the entire customer journey. Creating a bot on the Morph ...
    • [WhatsApp] WhatsApp Business Account Activation Process

      Get your business approved on WhatsApp This is done by submitting the Business Approval application on Morph.ai. You can find the link to it and more details in your logged in account at https://app.morph.ai/#home WhatsApp Number Activation Once we ...
    • 3.03 What are the WhatsApp/Facebook Policies for 24 hour limit

      Morph.ai is very cautious when it comes to abiding by the Facebook/WhatsApp Compliances. We strictly follow Facebook/WhatsApp guidelines for both Announce and Workflows.  Facebook lays specific rules that need to be followed while sharing promotional ...
    • 3.06 How to create Template Messages

      A message template is one of the multi-utility feature on the Morph.ai platform that not only makes your work easy, but is also used for raising request  with WhatsApp for post session approvals. As the name suggests, we can create a message block ...
    • [Configure] Source

      Morph.ai platform provides multiple ways for you to bring the user to the bot- Facebook ads, Email/SMS campaigns or Google ads. Based on the source, the platform provides you multiple widgets for attracting new customers and communicating with your ...