Skip to content

deltachat-bot/deltabot-cli-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

109 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deltabot-cli for Go

Latest release Go Reference CI Coverage Go Report Card

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.

Install

go get -u github.com/deltachat-bot/deltabot-cli-go/v2

Installing deltachat-rpc-server

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/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.

Usage

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 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/chatmail/rpc-client-go library, check its documentation to better understand how to use the Delta Chat API.

About

Go library to speedup Delta Chat bot development

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors