0

I use a Dialogflow API as NLP and the interface that we use is Whatsapp API. my problem is, when I want to bypass Text and Whatsapp client number to Dialogflow (my reference), I didn't found document to explain that. for comparison, the Telegram official integration dialogflow, from the body request we can extract that data like name and Telegram user ID.

  const sessionId = phone_number_id; //session ID get from phone number
  const sessionPath = sessionClient.projectAgentSessionPath(projectId, sessionId);

  const request = {
    session: sessionPath,
    queryInput: {
      text: {
        text: msg_body,
        languageCode: "id-ID"
      },
    },
    payload: {
      data: "testing",
      phoneNumber : phone_number_id
    }
  };
  console.log("request", request);
  await sessionClient.detectIntent(request).then(responses => {
    console.log("DetectIntent", JSON.stringify(responses));
  }).catch(err => {
    console.error("ERROR:", err);
  })

I tried it with request variable like that but in request body in dialogflow fulfillment, it never showed up

{
"responseId": "censored",
"queryResult": {
    "queryText": "halo",
    "action": "input.welcome",
    "parameters": {},
    "allRequiredParamsPresent": true,
    "fulfillmentText": "error",
    "fulfillmentMessages": [
        {
            "text": {
                "text": [
                    "error"
                ]
            }
        }
    ],
    "outputContexts": [
        {
            "name": "censored",
            "parameters": {
                "no-input": 0,
                "no-match": 0
            }
        }
    ],
    "intent": {
        "name": "censored",
        "displayName": "Default Welcome Intent"
    },
    "intentDetectionConfidence": 1,
    "languageCode": "id"
},
"originalDetectIntentRequest": {
    "payload": {}
},
"session": "censored"

}

  • Which tool are you using to integrate whatsapp and Dialogflow es? There is no direct integration between WhatsApp and Dialogflow, you can integrate using [Twilio](https://github.com/GoogleCloudPlatform/dialogflow-integrations/tree/master/twilio#readme). – Prajna Rai T Sep 23 '22 at 09:08
  • I use a custom integration, but I found this [link](https://stackoverflow.com/questions/47583996/send-parameters-to-webhook-on-dialogflow-sdk-v2) but thank you for your help – Maulana ahmad Sep 23 '22 at 12:03
  • Is your issue resolved? If so please provide the resolution steps as the answer. – Prajna Rai T Sep 23 '22 at 12:05

1 Answers1

0

@Maulana ahmad, As you have mentioned in the comment below example code can be referred to extract data from the body request.

const dialogflow = require('dialogflow');

// Import the JSON to gRPC struct converter
const structjson = require('./structjson.js');

// Instantiates a sessison client
const sessionClient = new dialogflow.SessionsClient();

// The path to identify the agent that owns the created intent.
const sessionPath = sessionClient.sessionPath(projectId, sessionId);

// The text query request.
const request = {
  session: sessionPath,
  queryInput: {
    event: {
      name: eventName,
      parameters: structjson.jsonToStructProto({foo: 'bar'}),
      languageCode: languageCode,
    },
  },
};

sessionClient
  .detectIntent(request)
  .then(responses => {
    console.log('Detected intent');
    logQueryResult(sessionClient, responses[0].queryResult);
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

This Stack Overflow link can be referred for more information.

Posting the answer as community wiki for the benefit of the community that might encounter this use case in the future.

Feel free to edit this answer for additional information.

Prajna Rai T
  • 1,666
  • 3
  • 15