skip to Main Content

the function below is supposed to provides the fulfillment to the share_your_phone_number intent.
When the intent is invoked, the share your phone number keyboard is displayed for the user in telegram.

function share_your_phone_number(agent) {
agent.add(`Welcome.`);
agent.add(new Payload("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"
          }
        ]
      ]
    }
  }
 ));
} 

When I deploy the API in the inline editor, only the “Welcome” string is returned in telegram bot chat. the key board buttons are not displayed.

I need a clue to fix fix this.

2

Answers


  1. Chosen as BEST ANSWER

    In creatin the Constructor for Payload object as documented [here]https://dialogflow.com/docs/reference/fulfillment-library/rich-responses#new_payloadplatform_payload, the platform and payload parameters are required.

    new Payload(platform, payload)

    The platform parameter is a property of WebhookClient object and should be defined as such (agent.SLACK, agent.TELEGRAM etc) assuming the webhookClient was instantiated and stored in agent

    Examples:

    agent.add(new Payload(agent.ACTIONS_ON_GOOGLE, {/*your Google payload here*/}); agent.add(new Payload(agent.SLACK, {/*your Slack payload here*/});

    agent.add(new Payload(agent.TELEGRAM, {/*your telegram payload here*/});

    ref: https://blog.dialogflow.com/post/fulfillment-library-beta/.

    For my use-case outlined in the question this is my full solution:

        // See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
        // for Dialogflow fulfillment library docs, samples, and to report issues
        'use strict';
    
        const functions = require('firebase-functions');
        const {WebhookClient} = require('dialogflow-fulfillment');
        const {Text, Card, Image, Suggestion, Payload} = require('dialogflow-fulfillment'); 
        process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
    
        exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
        const agent = new WebhookClient({ request, response });
        console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
        console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
    
        function welcome(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('Default Welcome Intent', welcome);
          agent.handleRequest(intentMap);
        });
    

  2. Here is my result:

      function welcome(agent) {
        const payload = {
          "text": "Pick a color",
          "reply_markup": {
            "inline_keyboard": [
              [
                {
                  "text": "Yellow",
                  "callback_data": "Yellow"
                }
              ],
              [
                {
                  "text": "Blue",
                  "callback_data": "Blue"
                }
              ]
            ]
          }
        };
    
        console.log('queryText ' + JSON.stringify(agent.request_.body.queryResult.queryText));
        console.log('displayName ' + JSON.stringify(agent.request_.body.queryResult.intent.displayName)
    
        agent.add(
          new Payload(agent.TELEGRAM, payload, {rawPayload: false, sendAsMessage: true})
        );
      }
    

    Also you must update version of dialogflow-fulfillment in package.json to latest. Now I have this version – "dialogflow-fulfillment": "^0.6.1"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search