Ty Cooper
Ty Cooper

Reputation: 51

How to use DialogFlow fulfilment and webhooks for Twilio?

I see that Dialogflow has fulfiment and webhook installations to allow for further dynamic and logistic control over the bot responses. I'm trying to peg a database on top of the webhook, but the channel I'm using is Twilio Text Messaging, and I'm having a little trouble with connecting the two. When I do activate fulfillment, the twilio bot does not read it. Any way to solve this?

I already created a few webhooks using Flask, and integrated it through fulfillment briefly using ngrok, but the bot is responding via the text responses I set for it. Its for google assistance, and facebook messenger, but not with the Twilio integration. I also tried using inlineJS to see if that held any difference to specifically define Twilio as the messaging outlet to use, however it did not peak success.

const functions = require('firebase-functions');
const {dialogflow} = require('actions-on-google');

const GOODLOCATION = 'location.good'
const NEARLOCATION = 'location.near'
const CHEAPLOCATION = 'location.cheap'
const WELCOME_INTENT = 'Default Welcome Intent'
const FALLBACK_INTENT = 'Default Fallback Intent'
const CRAVINGCULTUREINTENT = 'CravingCulture'
const CRAVINGITEM = 'CravingItem'

const app = dialogflow()

/*Supported Platforms*/

const PLATFORMS = {
  UNSPECIFIED: 'PLATFORM_UNSPECIFIED',
  FACEBOOK: 'FACEBOOK',
  SLACK: 'SLACK',
  TELEGRAM: 'TELEGRAM',
  KIK: 'KIK',
  SKYPE: 'SKYPE',
  LINE: 'LINE',
  VIBER: 'VIBER',
  ACTIONS_ON_GOOGLE: 'ACTIONS_ON_GOOGLE',
  TWILIO: 'TWILIO'
};

// Platforms that support Rich messaging
const SUPPORTED_RICH_MESSAGE_PLATFORMS = [
  PLATFORMS.FACEBOOK,
  PLATFORMS.SLACK,
  PLATFORMS.TELEGRAM,
  PLATFORMS.KIK,
  PLATFORMS.SKYPE,
  PLATFORMS.LINE,
  PLATFORMS.VIBER,
  PLATFORMS.ACTIONS_ON_GOOGLE,
  PLATFROM.TWILIO
];

app.intent(WELCOME_INTENT, (conv)=> {
  if(agent.requestSource === agent.TWILIO){
    conv.ask('This is working, Congratulations!')
  }
  else{
    conv.ask("Could not be served")
  }
});

app.intent(FALLBACK_INTENT, (conv)=> {
  conv.ask("I am unaware of that phrase, could you repeat that?")
});


exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)

I want the output to be any thing that the user insert through the twilio that this bot will respond accordingly to what is passed in.

Upvotes: 3

Views: 1032

Answers (1)

James Fernandes
James Fernandes

Reputation: 124

A little late, perhaps - hopefully this issue isn't still blocking/plaguing you.

I'm thinking you were intending:
if(agent.requestSource === PLATFORMS.TWILIO){
not:
if(agent.requestSource === agent.TWILIO){

However, also the value of agent.requestSource is actually lowercase "twilio".

Upvotes: 1

Related Questions