Giter VIP home page Giter VIP logo

show-around's Introduction

Show-Around: a Wit.ai Powered Facebook Messenger Bot

A Facebook Messenger Bot that will send you pictures of places you're interested in.

Bot screen

If you follow this short tutorial you will do the following:

  • Setup a Facebook Messenger bot with Node js
  • Integrate Wit.ai to your Bot
  • Add stories on Wit.ai

You can try it out here

I built this simple Bot for learning purposes, if you have any suggestion/fix please feel free to contribute :)

Setup

You can clone this project and use it as a starting point to build your own Bot.

1 - To get started you'll need to create a Facebook App and Page, you can find an up to date How-To guide here (just follow the App configuration part, no need to write any code yet)

To make your bot work your webhook URL needs to be in https, this is a requirement from facebook, you have many options for hosting your Bot:

2 - Sign up on Wit.ai and create an App.

3 - Clone this repository:

git clone https://github.com/youssef06/show-around.git

4 - Install dependencies

npm install

5 - Create parameters.js: This is an environment specific file, it contains all necessary API keys and tokens

module.exports = {
    //go to https://developers.facebook.com > your App page > go to Products > Messenger> under 'Token Generation' select your App, then just copy the token
    PAGE_ACCESS_TOKEN: '________',
    // the token you entered in step 1 when setting up your webhooks 
    VALIDATION_TOKEN: '_________',
    //Get this from your Facebook App dashboard
    APP_SECRET: '________',
    //From Google Console, this is used for Image search
    GOOGLE_MAPS_KEY: '________',
    //From the settings page of your Wit.ai App
    WIT_TOKEN: '_________'
};

6 - Say hello to your bot! It should echo back any message you write

Create your Stories

We've got our bot setup, but for now all it does is just echo back whatever we write to it, it's still not using Wit.ai, let's fix that.

Create a Wit.ai story:

As explained on Wit.ai:

"You will teach Wit by example, and each example conversation is called a Story"

  • So let's create a story: Create a story on Wit.ai "merge" and "get-image" are actions that are defined in index.js, make sure to comment the sendTextMessage call, and uncomment the block below like this:
//echo back the message
//bot.sendTextMessage(senderId, messageText);

// We retrieve the user's current session, or create one if it doesn't exist
// This is needed for our bot to figure out the conversation history
const sessionId = findOrCreateSession(senderId);

// Let's forward the message to the Wit.ai Bot Engine
// This will run all actions until our bot has nothing left to do
wit.runActions(
    sessionId, // the user's current session
    messageText, // the user's message
    sessions[sessionId].context // the user's current session state
).then((context) => {
    //context has been potentially modified by one of our wit actions
    // Our bot did everything it has to do.
    // Now it's waiting for further messages to proceed.
    console.log('Waiting for next user messages');
    console.log('Reinitializing session');
    delete sessions[sessionId];
    // Updating the user's current session state
    //sessions[sessionId].context = context;
}).catch((err) => {
    console.error('Oops! Got an error from Wit: ', err.stack || err);
});

If you test your bot again with something like:

"Show me a picture of London"

It should send you back a picture of London.

  • Let's try to help our bot understand more variations: Go to the "understanding" tab: Understanding on Wit.ai

Notice that in the 3rd example

"What's the weather in Manchester?"

The intent is not to get a photo of Manchester, the more variations we teach it the more accurate our results will be.

Todo

Add more capabilities to the Bot:

  • Greetings
  • Asking for location if not specified
  • It would be nice to send the user links to Google Street View, that would be better than simple images.

show-around's People

Contributors

youssef06 avatar

Watchers

 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.