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/v2This 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/chatmail/core/tree/main/deltachat-rpc-server
WARNING: Install the version of deltachat-rpc-server that matches the version of this package,
different versions might be incompatible and cause unexpected errors.
Example echo-bot written with deltabot-cli:
package main
import (
"github.com/chatmail/rpc-client-go/v2/deltachat"
"github.com/deltachat-bot/deltabot-cli-go/v2/botcli"
"github.com/spf13/cobra"
)
func main() {
cli := botcli.New("echobot")
cli.OnBotInit(func(cli *botcli.BotCli, bot *deltachat.Bot, cmd *cobra.Command, args []string) {
// incoming message handling
bot.OnNewMsg(func(bot *deltachat.Bot, accId uint32, msgId uint32) {
msg, _ := bot.Rpc.GetMessage(accId, msgId)
if msg.FromId > deltachat.ContactLastSpecial && msg.Text != "" {
_, _ = bot.Rpc.SendMsg(accId, msg.ChatId, deltachat.MessageData{Text: &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 dcaccount:nine.testrun.org
go run ./echobot.go serveUse 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/chatmail/rpc-client-go library, check its documentation to better understand how to use the Delta Chat API.