Created
August 21, 2019 07:10
-
-
Save deepakmahakale/793136c9bc6f492612949eda8749296f to your computer and use it in GitHub Desktop.
A twilio function used for NLU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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