skip to Main Content

For the ‘test intent’, I have enabled the Enable Webhook Call for this intent
I have correctly setup Telegram integration to the bot.

In the fullfilment code, I am using the Constructor for Payload object(https://dialogflow.com/docs/reference/fulfillment-library/rich-responses#new_payloadplatform_payload)and I have specified the string indicating target platform of payload. Please see in code below the welcome function:

    const {WebhookClient} = require('dialogflow-fulfillment');
    const {Text, Card, Image, Suggestion, Payload} = require('dialogflow-fulfillment'); 

    exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
    const agent = new WebhookClient({ request, response });

    function test(agent) {
      agent.add(new Payload(agent.TELEGRAM, {

        "text": "Please click on button below to share your number",
        "reply_markup": {
          "one_time_keyboard": true,
          "resize_keyboard": true,
          "keyboard": [
            [
              {
                "text": "Share my phone number",
                "callback_data": "phone",
                "request_contact": true
              }
            ],
            [
              {
                "text": "Cancel",
                "callback_data": "Cancel"
              }
            ]
          ]
        }
       }));
      }

      // Run the proper function handler based on the matched Dialogflow intent name
      let intentMap = new Map();
      intentMap.set('test Intent', test);
      agent.handleRequest(intentMap);
       });

Dialogflow is not returning the payload response in the fulfillment code to telegram on invocation of the intent.
I have taken a look at the project function logs but their is no errors being logged.
Their is no reason for my code not to work

Is the payload class deprecated in dialogflow?

2

Answers


  1. Chosen as BEST ANSWER

    The dialogflow WebhookClient used in the Dialogflow fulfillment webhook logic returns an Express HTTP response object that contains the send method. I hooked into this method to send response back to dialogflow's webhook fulfillment API. See code below.

    function telegramIntegration(agent) {
    
      const ClientResponse=
      {
        "ClientResponse": [
          {
            "payload": {
              "telegram": 
              {
                "text": "Please share your contact",
                "reply_markup": {
                  "keyboard": [
                    [
                      {
                        "text": "Share my phone number",
                        "callback_data": "phone",
                        "request_contact": true
                      }
                    ],
                    [
                      {
                        "text": "Cancel",
                        "callback_data": "Cancel"
                      }
                    ]
                  ],
                  "one_time_keyboard": true,
                  "resize_keyboard": true
                }
              }
            }
          }
        ]
      };
    
      response.send(JSON.stringify(ClientResponse));
    }
    

    However this work-around does not answer my question "Is the Dialogflow Payload Class deprecated?"


  2. I had the same problem today and with this is running now

            var pl_tl = {
                "telegram": {
                    "text": "Please click on button below to share your number",
                    "reply_markup": {
                        "one_time_keyboard": true,
                        "resize_keyboard": true,
                        "keyboard": [
                            [
                                {
                                    "text": "Share my phone number",
                                    "callback_data": "phone",
                "request_contact": true
                                }
                            ],
                            [
                                {
                                    "text": "Cancel",
                                    "callback_data": "Cancel"
                                }
                            ]
                        ]
                    }
                }   
            }
    
    
            let pl = new Payload(agent.TELEGRAM, pl_tl, { sendAsMessage: true, rawPayload: true });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search