Skip to content

deltachat-bot/deltabot-cli-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 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

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/deltachat/deltachat-core-rust/tree/master/deltachat-rpc-server

Usage

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 [email protected] 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.

Template project

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

About

Go library to speedup Delta Chat bot development

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published