Giter Club home page Giter Club logo

dialogflow-adapter-whatsapp-js's Introduction

WATI.io Dialogflow WhatsApp Adapter

This Dialogflow WhatsApp adapter allows you to add an additional endpoint to your bot for connect to the Whatsapp channel and get the response from Dialogflow.

Prerequisites

Apply through WhatsApp Solution Partner e.g. WATI.io

Installation

  • To run the package, run npm install with the full path to your package directory:

    npm install @wati.io/dialogflow-adapter-whatsapp
    
  • get the Dialogflow token from google cloud (go the Google Cloud Platform to enable the Dialogflow API and downland the API token JSON file)

  • save the token json file to root directory

  • save the the path of the token file to env variable GOOGLE_APPLICATION_CREDENTIALS , we suggest you use dotenv and save it to the .env file

process.env.GOOGLE_APPLICATION_CREDENTIALS = "C:\Users\user\xxx\xxx\xxx\NewAgent-xxxxx.json"

Usage

const WhatsAppAdapter = require('@wati.io/dialogflow-adapter-whatsapp');
  • get the user request from whatsapp
const wsAdapter = new WhatsAppAdapter({
    endpoint: 'https://whatsapp-apixxxxxx',// whatsapp endpoint
    token: 'xxxxxxxxxxxx', //The token you get from /v1/users/login, it will be used by default
    password: 'Basic xxxxxxxxxxx', //Basic base64(username:password) , it will be use to get the token from /v1/users/login, if you let `token` empty
    projectId: projectId, // your Dialogflow projectId
    sessionId: sessionId, // session of this conversation, e.g. 123456
    languageCode: languageCode //e.g. en, https://cloud.google.com/dialogflow/docs/reference/language
});

// WhatsApp endpoint
server.post('/api/whatsapp/messages', (req, res) => {
    wsAdapter.processActivity(req, res).then(async (context) => {
        console.log("user say: " + context.activity.text.body)
        await context.sendActivity("echo: " + context.activity.text.body);
    });
});

// get the response of the Dialogflow
await wsAdapter.getIntent(queries).then(async (replyText) => {
     await context.sendActivity(replyText);
});

Further reading

dialogflow-adapter-whatsapp-js's People

Contributors

codyhon avatar kenyeung128 avatar

Stargazers

Luciana  avatar Rhutik Giradkar avatar  avatar Jitesh avatar Lupamo Anjichi avatar C A avatar Rahmat Ramadhan avatar ilkan avatar Jose Luis avatar

Watchers

James Cloos avatar  avatar Jitesh avatar

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.