0

I have to share information from my chatbot working on dialogflow to a human team using SMS. I am using fullfilment to trigger twilio to use my twilio number to send a SMS to the team phone number.

The code is as below

'use strict';
 
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const accountSid = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; 
const authToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const twilio = require('twilio')(accountSid, authToken);

function enviarmensagem(usuario){
    // Configurações da transmissão
const client = new twilio(accountSid, authToken);
    client.messages
      .create({
          body: 'Teste OK',
          to: '+55XXXXXXXXXX',  // Envie uma mensagem a esse número
          from: '+1XXXXXXXXXXX' // Através do meu número Twilio
      })
     .then((message) => console.log(message.sid));
}
  
// Criação da Função no Firebase
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {

  // Definição do objeto controlador do 'agent'
  const agent = new WebhookClient({ request, response });

 // 'Handler' para enviar mensagem
  function enviarmensagem(agent) {
    agent.add('Mensagem enviada');
    enviarmensagem(agent.session);
  }
  
  // Executar a função adequada de acordo com a Intent recebida
  let intentMap = new Map();
  intentMap.set('Teste mensagem', enviarmensagem);

  try{
    agent.handleRequest(intentMap);
  }
  catch(e){
      console.log(e);
  }
});

PACKAGE.JSON

{
  "name": "dialogflowFirebaseFulfillment",
  "description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
  "version": "0.0.1",
  "private": true,
  "license": "Apache Version 2.0",
  "author": "Google Inc.",
  "engines": {
    "node": "10"
  },
  "scripts": {
    "lint": "semistandard --fix \"**/*.js\"",
    "start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
    "deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
  },
  "dependencies": {
    "actions-on-google": "^2.2.0",
    "firebase-admin": "^5.13.1",
    "firebase-functions": "^2.0.2",
    "dialogflow": "^0.6.0",
    "dialogflow-fulfillment": "^0.6.1",
    "twilio": "^3.29.2",
    "nodemailer": "^4.7.0"
  }
}

However it is returning the following Fullfilment status

Webhook call failed. Error: DEADLINE_EXCEEDED, State: URL_TIMEOUT, Reason: TIMEOUT_WEB.

Deploy is working with no errors.

Could someone help me to find where my mistake is?

1 Answers1

0

The function needs to return something in order to complete the webhook call. See the documentation on what would classify as an ok response