Skip to content

Instantly share code, notes, and snippets.

@deepakmahakale
Created August 21, 2019 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepakmahakale/793136c9bc6f492612949eda8749296f to your computer and use it in GitHub Desktop.
Save deepakmahakale/793136c9bc6f492612949eda8749296f to your computer and use it in GitHub Desktop.
A twilio function used for NLU
/**
* Hindi Voice Bot
*
* This function lets you ask questions in Hindi and get a proper response
*/
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse()
if(event.SpeechResult) {
var got = require('got');
var requestPayload = {
lang: 'hi',
query: event.SpeechResult,
sessionId: '12345'};
got.post('https://api.dialogflow.com/v1/query?v=20150910',
{ body: JSON.stringify(requestPayload),
headers: {
Authorization: 'Bearer ' + context.AUTH_TOKEN,
'accept': 'application/json',
'Content-Type': 'application/json'
}
}).then(function(response) {
body = JSON.parse(response.body)
twiml.gather({input: 'speech', language: 'hi-IN'})
.say(body.result.fulfillment.speech)
callback(null, twiml);
}).catch(function(error) {
console.log(error)
callback(error)
});
}
else{
twiml.gather({input: 'speech', language: 'hi-IN'})
.say('Namaste. Aap muzse bharat se judey kuchh sawaal puchh sakte hai', { voice: 'Polly.Aditi'})
callback(null, twiml)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment