Giter Site home page Giter Site logo

0xanon101 / dialogflow-nodejs-webhook Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 13 KB

There are some method to call the api.ai or dialogflow . One of the method that i have done is to define a custom template to call the dialogflow with a response from our express server .

JavaScript 100.00%
webhook dialogflow-v2 dialogflow-fulfillment nodejs expressjs serveo google-home sample-template webhook-template

dialogflow-nodejs-webhook's Introduction

dialogflow-nodejs-webhook

There are different ways to call the api.ai or dialogflow . But for this demo , we will be using one of the method to define a custom webhook to call the dialogflow with a response from our Express Server .

Here's the documentation :

Express

๐Ÿ”ฅ Express ๐Ÿš€ Serveo

First create a Express server on index.js

const express= require('express');
const app =  express();
require('./routes')(app);

const PORT = process.env.PORT  || 3000;
const serveoPORT  = "<<Put_your_serveo_url>>";
app.listen(PORT  ,() =>  {
    console.log(`The ngrok server is  ${serveoPORT} \n express server is listening on ${PORT}`)
})

Then create a single POST route for the webhook on routes.js and include it in index.js (look above ๐Ÿค˜ )

Use **node_fetch** for making async request to third party library to get some data

const fetch = require('node-fetch');
module.exports = (app) => {

    app.post('/moviebot/get-movie-details', (req, res) => {
                      fetch('<<your_external_url>.')
                        .then( data => {
                          res.json({
                              "fulfillmentText": data,
                              "source": "get-top-rated-movies"
                          });
                       }).catch(error => console.log(error.message));
                
        });
}

Here the response key I am sending is predefined by the dialogflow fulfillment API

  res.json({
          "fulfillmentText": data,
          "source": "get-top-rated-movies"
       });

It does have other key value pair too for sending Rich text messages into the Dialgflow api Here's the Different type of Response you can send through your res.json() call :

๐Ÿš€ DialogFlow Docs Look upon the v2 API.

Next step, is to install serveo:
๐ŸŽ‰ Serveo

Serveo

Serveo is an SSH server just for remote port forwarding. When a user connects to Serveo, they get a public URL that they can use to connect to their localhost server , in this case it's our local Express Server , to tunnel all the public request to Severo URL from dialogflow fulfillment endpoint. We will mention the Public URL in Dialogflow as our endpoint flows control to ---> Express server running.

Run:

ssh -R 80:localhost:3000 serveo.net

That's it . You have completely set up your nodejs webhook . Good luck Exploring , Thanks.

dialogflow-nodejs-webhook's People

Contributors

0xanon101 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

dashbaord202401

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.