cancel
Showing results for 
Search instead for 
Did you mean: 

How to render button or quick replies in whatsapp using twilio?

S0024009236
Participant
0 Kudos

Hello experts,

I was trying to connect sap cai with whatsapp. I referred to the blog SAP CAI WITH WHATSAPP. I had to make some minor changes as sap cai has changed the way of authentication and hence default sdk can't be used.

Following is the code I wrote in twilio function and the response of it. How do i send buttons or quick replies to whaatsapp?

//Code in twilio function
exports.handler = function(context, event, callback) {
    let twiml = new Twilio.twiml.MessagingResponse();   
    let superagent = require('superagent'); 
   
superagent
 .post("https://api.cai.tools.sap/build/v1/dialog")
  .send({ message: { content: event.Body, type:"text" }, conversation_id: event.From})
  .set("Authorization", "<Bearer using client id and secret>); 
  .set("X-Token", "<Developer Token>")
  .set("Content-type", "application/json")
  .then(function(res) {
   data = res.text;
   //console.log(data);
   twiml.message(data);
   callback(null, twiml);
  });
        
 
};
//response
{
    "results": {
        "nlp": {
            "uuid": "38db853d-ee77-4ffb-94c5-6839c86e7bfd154100",
            "source": "fdfd",
            "intents": [],
            "entities": {},
            "act": null,
            "sentiment": "neutral",
            "language": "un",
            "processing_language": "en",
            "version": "2105.0.0",
            "timestamp": "2021-06-16T13:32:46.369068+00:00",
            "status": 200,
            "type": null,
            "logs": []
        },
        "messages": [
            {
                "type": "buttons",
                "content": {
                    "title": "Select Language",
                    "buttons": [
                        {
                            "value": "english",
                            "title": "English",
                            "type": "postback"
                        },
                        {
                            "value": "hindi",
                            "title": "हिंदी",
                            "type": "postback"
                        },
                        {
                            "value": "marathi",
                            "title": "मराठी",
                            "type": "postback"
                        },
                        {
                            "value": "kannada",
                            "title": "ಕನ್ನಡ",
                            "type": "postback"
                        }
                    ]
                },
                "delay": null
            }
        ],
        "conversation": {
            "id": "whatsapp:+919579xxxxxx",
            "language": "en",
            "memory": {
                "flag_conv_init": 1
            },
            "skill": "detect-lang",
            "skill_occurences": 1,
            "skill_id": "431288ed-6cc1-4049-9b23-8d57e240c8a2"
        },
        "logs": null,
        "qna": null,
        "fallback": null
    },
    "message": "Dialog rendered with success"
}

Accepted Solutions (0)

Answers (0)