MIT License
A framework to build chatbot compatible with different platforms! The idea is simple, develop chatbots in the same way do implement web applications via Spring Web.
A simple Example:
public class MessageEchoExample {
@OnCommand(value = "echo", help = "This command echo")
public Response onEchoCommand(Command command, Context context) {
return Response.asText("echo " + command.name());
}
// space star at the end of command name let arguments in
@OnCommand(value = "echo *", help = "This command echo")
public Response onEchoStarCommand(Command command, Context context) {
return Response.asText(command.name().substring(5));
}
}
@OnEvent
annotation case be used in order to perform an action based
on events in the group. Example below demonstrates how to implement a welcome message for new members.
@OnEvent("NEW_CHAT_MEMBER")
public Response onNewMember(Event<UserEventPayload> event, Context context) {
return Response.asText("Khosh oomadi lanati %s!".formatted(event.getPayload().getFirstName()));
}
Below are some ideas I'll implement in the comming days, no promise to respect the order though!
To test the example you need to run the shell script called set_telegram_webhook.sh
in root folder
following steps might be needed:
Install jq
. jq is a lightweight and flexible command-line JSON processor:
sudo apt install jq
sudo brew install jq
Install ngrok
:cross-platform application that enables developers to expose a local development server to the Internet with minimal effort:
ngrok*.zip
from: here
unzip*.zip
./ngrok authtoken <your_auth_token>
sudo mv ngrok /usr/local/bin
ngrok http 80
Get your currently existing bot API from telegrams botfather or create one.
Once you have your API Key ready, run this script. Replace TELEGRAM_API_KEY with your API Key:
resources/application.yml
./set_telegram_webhook.sh 8080 /connectors/telegram TELEGRAM_API_KEY
If everything is fine you will see:
{"ok":true,"result":true,"description":"Webhook is already set"}
Send a simple hi
message to your bot to check if its working. have fun.