Morph.ai Help Center

            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"]
            }
            PropertyDescriptionRequired
            accountIdThis is the ID of your ‘WhatsApp Account’. Request this id by sending an email on support@morph.aiY
            templateIdThis is the ID of the ‘Message Template’. This is available in the URL of each message template.

            Y
            customerDataThis 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
            postSessionParamsThis 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: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlkIjoiNWNhYzc3ZmNlMWE3NTQ2ZWQwZGIyMmMzIn0.eyJzY29wZSI6ImFwaSJ9.9q2QpFpzOepSf4KQmUDVvHUo07BxFzYdsxL_cn8Wm3w' \
              -H 'Content-Type: application/json' \
              -d '{
                "customerData": {
                    "Phone Number": "+918602294324"
                },
                "accountId":"5d777ef178cc21352be85bdf",
                "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": "+918602294324",
                        "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 POST \
              https://open-api.morph.ai/v1/customer/wa/create \  
              -H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImlkIjoiNWNhYzc3ZmNlMWE3NTQ2ZWQwZGIyMmMzIn0.eyJzY29wZSI6ImFwaSJ9.9q2QpFpzOepSf4KQmUDVvHUo07BxFzYdsxL_cn8Wm3w' \
              -H 'Content-Type: application/json' \
              -d '{
                "customerData" : {
                "First Name"   : "Vipul Test"
                }
            }'
            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": "+918602294324",
                        "bl___isRU": false,
                        "tx___fN": "Vipul Test",
                        "tm___lMT": 1568113903291,
                        "bl___iAs": false
                    }
                }
            }


            Updated: 06 Oct 2019 09:03 PM
            Helpful?  
            Help us to make this article better
            0 0