Giter Club home page Giter Club logo

facebook-chatbot-python's Introduction

facebook-chatbot-python

A simple python chatbot for Facebook Messenger.

The bot reads incoming Facebook Messenger messages, and responds by generating random text from a corpus. The length of the response is randomly selected around the length of the incoming message, and a random word from the incoming message is selected as the starting word of the response.

Installing dependencies

Use of virtualenv is highly recommended, especially since the old version of nltk used requires an old version of setuptools.

$ pip install -r requirements.txt

Setting up a Facebook app for Facebook messenger

  • You're going to need a publicly routed https address. I used ngrok to create a tunnel to my local development machine.
  • The server will need to be started for you to verify the webhook. See "Starting the server" below.
  • Follow the instructions provided in the Facebook quickstart tutorial for creating a page and an app.
  • Set the VERIFY_TOKEN and FACEBOOK_TOKEN environment variables to the values you get from following the tutorial.

Building a corpus

Before you start the server, there has to be a file called corpus.txt in the root directory. This can be any text, but I found it interesting to use all of my sent emails as the corpus.

If you have your emails in mbox format (you can get them from Gmail using Google Takeout), you can use the provided mail_corpus.py to build a corpus.

$ python mail_corpus.py emails.mbox [email protected] [email protected] ...

This will grab the text from all emails from the specified addresses (it tries to not include text responded to, signatures and so on), and create a corpus from it.

Starting the server

Is just a matter of

$ python server.py

TODO

  • A big corpus takes a loooong time to load
  • Tests
  • Send structured messages
  • Handle postbacks

facebook-chatbot-python's People

Contributors

hult avatar

Watchers

James Cloos 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.