Library to speedup Delta Chat bot development in Golang.
With this library you can focus on writing your event/message processing logic and let us handle the repetitive process of creating the bot CLI.
go get -u github.com/deltachat-bot/deltabot-cli-go
This package depends on a standalone Delta Chat RPC server deltachat-rpc-server
program that must be
available in your PATH
. For installation instructions check:
https://github.com/deltachat/deltachat-core-rust/tree/master/deltachat-rpc-server
Example echo-bot written with deltabot-cli:
package main
import (
"github.com/deltachat-bot/deltabot-cli-go/botcli"
"github.com/deltachat/deltachat-rpc-client-go/deltachat"
"github.com/spf13/cobra"
)
func main() {
cli := botcli.New("echobot")
// incoming message handling
cli.OnBotInit(func(cli *botcli.BotCli, bot *deltachat.Bot, cmd *cobra.Command, args []string) {
bot.OnNewMsg(func(bot *deltachat.Bot, accId deltachat.AccountId, msgId deltachat.MsgId) {
msg, _ := bot.Rpc.GetMessage(accId, msgId)
if msg.FromId > deltachat.ContactLastSpecial && msg.Text != "" {
bot.Rpc.MiscSendTextMessage(accId, msg.ChatId, msg.Text)
}
})
})
cli.OnBotStart(func(cli *botcli.BotCli, bot *deltachat.Bot, cmd *cobra.Command, args []string) {
cli.Logger.Info("OnBotStart event triggered: bot is about to start!")
})
cli.Start()
}
Save the previous code snippet as echobot.go
then run:
go mod init echobot; go mod tidy
go run ./echobot.go init bot@example.com PASSWORD
go run ./echobot.go serve
Use go run ./echobot.go --help
to see all the available options.
Check the examples folder for more examples.
This package depends on https://github.com/deltachat/deltachat-rpc-client-go library, check its documentation to better understand how to use the Delta Chat API.
To help you quickly creating new bots, we have prepared a project template with all the basic boilerplate, including unit tests, linter and GitHub CI to test and release your bot. Check it here: https://github.com/deltachat-bot/echobot-go