GoogleCloudPlatform / dialogflow-integrations

Dialogflow integrations with multiple platforms including KIK, Skype, Spark, Twlio, Twitter and Viber
https://cloud.google.com/dialogflow/
Apache License 2.0
247 stars 499 forks source link

server.js #170

Open AxlReyesY opened 2 years ago

AxlReyesY commented 2 years ago

/**

app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true }));

//For authenticating dialogflow_session_client.js, create a Service Account and // download its key file. Set the environmental variable // GOOGLE_APPLICATION_CREDENTIALS to the key file's location. //See https://dialogflow.com/docs/reference/v2-auth-setup and // https://cloud.google.com/dialogflow/docs/setup for details.

const projectId = 'PRUEBA'; const phoneNumber = "14155238886"; const accountSid = 'AC2b4a7e397baff68fdf6a3b86837b7d0b'; const authToken = '4f67b167a1adceab80898a33d1bf9538';

const client = require('twilio')(accountSid, authToken); const MessagingResponse = require('twilio').twiml.MessagingResponse; const sessionClient = new dialogflowSessionClient(projectId);

const listener = app.listen(process.env.PORT, function() { console.log('Your Twilio integration server is listening on port '

app.post('/', async function(req, res) { const body = req.body; const text = body.Body; const id = body.From; const dialogflowResponse = (await sessionClient.detectIntent( text, id, body)).fulfillmentText; const twiml = new MessagingResponse(); const message = twiml.message(dialogflowResponse); res.send(twiml.toString()); });

process.on('SIGTERM', () => { listener.close(() => { console.log('Closing http server.'); process.exit(0); }); });