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.
- Response Models: Russenger provides various response models to handle different types of responses. These include:
- Data struct: A struct to store and manipulate data with a value and an optional page.
- Req struct: A struct to create and manipulate requests with a host field.
- Deserialization: Deserialize the value of the data into a specified type with the
get_valuemethod. - Page retrieval: Retrieve the page of the data with the
get_pagemethod.
New Features
- ButtonModel: A model to create and manipulate buttons in messages.
- GetstartModel: A model to handle the "Get Started" button in Messenger.
- PersistenceMenuModel: A model to handle persistent menus in Messenger.
- SenderActionModel: A model to handle sender actions like typing indicators.
Installation
Install generate first if it's not yet installed
Create project with template
How To Use
Project
Example
Here's an example of how to use Russenger to handle different actions in a chatbot:
Russenger Cargo.toml
= "0.1.3"
= "0.5"
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 *;
create_action!;
create_action!;
create_action!;
russenger_app!;
Who to get User Input
use *;
create_action!;
create_action!;
russenger_app!;
How to send file from static
create_action!;
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.