Skip to content
/ gobot Public

🤖 Messenger chatbot using the Levenshtein distance algorithm for pattern matching. Easily configurable with yaml files. Use mux and yaml.v2.

License

Notifications You must be signed in to change notification settings

hbollon/gobot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gobot : Messenger ChatBot Golang

Go Report Card License: MIT

Facebook Messenger chatbot using the Levenshtein distance algorithm for pattern matching. Use mux and yaml.v2.


Table of Contents


Requirements

  • Go
  • Facebook account

Presentation

This chatbot was developed in order to manage efficiently any facebook page. It use Facebook API. Gobot use Levenshtein distance algorithm for pattern matching to calculate a match percentage between the received message and templates defined in content.yml in order to be more flexible for the interlocutor instead of only responding to messages that match exactly. For example, if you have set a minimal matching percentage of 40 % and defined patterns like this in content.yml :

templates: 
- messages: ["Hello", "Hi"]
response: "Hi !\nI'm GoBot chat bot ! :)"
- messages: ["Who's your creator ?"]
response: "I was build by @hbollon from Bits Please Inc. :)\nMy source code is available on his Github : github.com/hbollon !"

default_response: "Sorry, I don't understand your message... :/\nPlease try again with different sentence or using more words."

And someone sends you "Who's build you ?" It will match with "Who's your creator ?" and send back corresponding response ! Same with "Creator" :)

However, if it doesn't match with any template, it will send the default_response. You can edit the minimal matching percentage in the config.yml file.

Features

  • Designed for Facebook Messenger ✨
  • Easily configurable through yaml files ✨
  • Efficient pattern matching with Levenshtein distance ✨
  • Customizable minimal matching percentage ✨

Installation

Clone

  • Firstly, clone this repo wherever you want using :
git clone https://github.com/hbollon/gobot

Setup

page

  • Configure your webhook Callback URL (You can use Ngrok to make public URL to your localhost for testing purpose), the Verify Token and subscribe to messages field:

webhook

  • Edit configs/config.yml file with your Messenger App credentials :
# Facebook API config
app_secret: <app_secret> # Secret key which can be found in the app settings on Facebook Developer dashboard
access_token: <facebook_app_token> # Generated token on app Messenger product
verify_token: <webhook_verify_key> # Verify token of your webhook URL 

You can copy config.yml.exemple to config.yml and replace corresponding values.

  • Open bash in root project directory and run :
go run cmd/gobot/*.go # Run program without build it
# or
go build cmd/gobot/*.go && ./gobot # Build and run

Customize chatbot responses

In order to modify the messages that your chatbot will recognize as well as the responses that it will send back, you just need to modify the content.yml file in the config folder.

Exemple:

templates: 
    - messages: ["Hello", "Hi"]
      response: "Hi !\nI'm GoBot chat bot ! :)"
    - messages: ["Who's your creator ?"]
      response: "I was build by @hbollon from Bits Please Inc. :)\nMy source code is available on his Github : github.com/hbollon !"

default_response: "Sorry, I don't understand your message... :/\nPlease try again with different sentence or using more words."

A template is composed of messages which are the sentences on which the bot is based to try to understand the interlocutor via the Levenshtein algorithm. If the received message matches one of these messages (depending on the match threshold defined in config.yml) then the response contained in the response attribute will be sent to the user. If received message don't match with any template, the bot will send back the default_response.

Author

👤 Hugo Bollon

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2020 Hugo Bollon.
This project is MIT License licensed.