Russenger - Facebook Messenger Webhook Handling in Rust

Russenger is a Rust library designed to simplify the handling of Facebook Messenger webhook responses. It offers a convenient way to construct and send various types of responses, including text messages, quick replies, generic templates, and media attachments.
Features
Russenger provides the following features:
- Text messages: Send text messages to users.
- Quick replies: Send quick replies with buttons to users.
- Generic templates: Send generic templates with images, titles, and buttons to users.
- Media attachments: Send media attachments such as images, audio, and video to users.
- Webhook verification: Verify incoming webhook requests from Facebook.
- Button: A model to create and manipulate buttons in messages.
- Getstart: A model to handle the "Get Started" button in Messenger.
- PersistenceMenu: A model to handle persistent menus in Messenger.
- Action: A model to handle sender actions like typing indicators.
- Actix-web Integration: Russenger continues to leverage Actix-web for improved speed and performance in handling Messenger webhook responses.
New Features
- SeaORM Integration: sea_orm Russenger now leverages SeaORM for improved database operations.
Old Method with create_action!
use *;
create_action!;
New Method with #[action]
use *;
async
In both examples, we define an action Main that sends a welcome message if the user input is "Hello". The new method using #[action] is more concise and easier to read.
How to Create new Project
-
1: Install Cargo Generate
-
2: Generate new project
How To Use
Example
Here's an example of how to use Russenger to handle different actions in a chatbot:
Russenger Cargo.toml
= "0.1.6"
= "4"
Environnement .env
# You can change this
PORT=6969
HOST=0.0.0.0
# change this
VERIFY_TOKEN=<your-verify-token>
# change this
PAGE_ACCESS_TOKEN=<your-page-access-token>
#### postgres
# DATABASE=postgres://<user>:<password>@<host>/<db_name>
#### mysql
# DATABASE=mysql://<user>:<password>@<host>/<db_name>
#### sqlite
DATABASE=sqlite:<db_name>
Code src/main.rs
use *;
async
async
async
russenger_app!;
Who to get User Input
use *;
async
async
russenger_app!;
How to send file from static
use *;
async
russenger_app!;
Run
Migrate Database run it once
if you use sqlite as Bb
Runserver
In this example, we define three actions: Main, Option1, and Option2. Each action is associated with a function that handles the action. The Main action sends a text message and a quick reply with two options. The Option1 and Option2 actions handle the user's selection of the respective options.
EndPoint
-
GET
/webhook: Verify your chatbot with Facebook Messenger. Facebook will send a challenge, and your bot must respond correctly for verification. -
POST
/webhook: This is where Facebook Messenger sends messages from users. Handle incoming messages and respond accordingly here.