Skip to content

Commit d21739b

Browse files
authored
deltabot-cli (python and Go) (#67)
* Python deltabot-cli * add go deltabot * adjust readme
1 parent ed3f5b0 commit d21739b

File tree

10 files changed

+230
-16
lines changed

10 files changed

+230
-16
lines changed

README.md

+16-14
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@ An echo bot in multiple languages to get you started.
44

55
### Direct:
66

7-
| Language | core version |
8-
| ------------------------------------------------------------ | ------------ |
9-
| [C](./c) | `1.132.1` |
10-
| [Go](./go) | `1.127.0` |
11-
| [node.js over cffi](./nodejs_cffi) | `1.132.1` |
12-
| [node.js over jsonrpc](./nodejs_napi_jsonrpc) (unmaintained) | `1.101.0` |
13-
| [Python over cffi](./python_cffi) | `1.132.1` |
14-
| [Python over jsonrpc](./python_jsonrpc) | `1.132.1` |
15-
| [Rust](./rust) | `1.132.1` |
7+
| Language | core version |
8+
| ------------------------------------------------------------ | ---------------------------------------------------------------------------- |
9+
| [C](./c) | `1.132.1` |
10+
| [Go](./go) | `1.127.0` (jsonrpc, newer core might work too, last tested with `v1.131.4` ) |
11+
| [node.js over cffi](./nodejs_cffi) | `1.132.1` |
12+
| [node.js over jsonrpc](./nodejs_napi_jsonrpc) (unmaintained) | `1.101.0` |
13+
| [Python over cffi](./python_cffi) | `1.132.1` |
14+
| [Python over jsonrpc](./python_jsonrpc) | `1.132.1` |
15+
| [Rust](./rust) | `1.132.1` |
1616

1717
### With abstraction layer / bot framework:
1818

19-
| Language | core version |
20-
| ------------------------------------------------------------- | -------------------------- |
21-
| [bot-base (node.js)](./nodejs_bot_base) (unmaintained) | `1.27.0` |
22-
| [deltabot (python)](./python_deltabot_plugin) (unmaintained?) | `?` |
23-
| [simplebot (python)](./python_simplebot_plugin) | `1.93.0 (simplebot 3.3.0)` |
19+
| Language | core version |
20+
| ------------------------------------------------------------- | ---------------------------------------------------------------------------- |
21+
| [deltabot-cli Python](./go_deltabot_cli) | `1.127.0` (jsonrpc, newer core might work too, last tested with `v1.131.4` ) |
22+
| [deltabot-cli Python](./python_deltabot_cli) | `v1.131.4` |
23+
| [simplebot (python)](./python_simplebot_plugin) | `1.93.0 (simplebot 3.3.0)` |
24+
| [deltabot (python)](./python_deltabot_plugin) (unmaintained?) | `?` |
25+
| [bot-base (node.js)](./nodejs_bot_base) (unmaintained) | `1.27.0` |
2426

2527
The bot just echos your text messages when you send them to it as DM.
2628

go_deltabot_cli/README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Go deltabot-cli
2+
3+
This example is about creating a bot with the bot framework [deltabot-cli-go](https://github.com/deltachat-bot/deltabot-cli-go/), which gives a hook based interface and a cli interface to configure your bot.
4+
5+
> This is a go framework for bots, see [../README.md](../README.md) for other approaches to write bot in go.
6+
7+
## Usage
8+
9+
> Per default the bot data and configuration is stored in your user directory
10+
> (`Library/Application Support/bot_name/`, `.config/bot_name/`, on windows probably in `%APPDATA%` <!-- todo the location on windows needs to be checked -->).
11+
>
12+
> You can change configuration location with `--folder` flag (`--folder PATH` or `-f PATH`).
13+
14+
### Setup
15+
16+
### Installing deltachat-rpc-server
17+
18+
For the bot to work, first `deltachat-rpc-server` program needs to
19+
be installed and available in your `PATH`. To install it from source run:
20+
21+
```sh
22+
cargo install --git https://github.com/deltachat/deltachat-core-rust/ deltachat-rpc-server
23+
```
24+
25+
For more info and pre-built binaries check:
26+
https://github.com/deltachat/deltachat-core-rust/tree/master/deltachat-rpc-server
27+
28+
#### Install
29+
30+
```sh
31+
go mod tidy
32+
```
33+
34+
#### Configure
35+
36+
```sh
37+
go run ./echobot.go init [email protected] password
38+
```
39+
40+
### Start
41+
42+
```sh
43+
go run ./echobot.go serve
44+
```

go_deltabot_cli/echobot.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"github.com/deltachat-bot/deltabot-cli-go/botcli"
5+
"github.com/deltachat/deltachat-rpc-client-go/deltachat"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func main() {
10+
cli := botcli.New("echobot")
11+
12+
// incoming message handling
13+
cli.OnBotInit(func(cli *botcli.BotCli, bot *deltachat.Bot, cmd *cobra.Command, args []string) {
14+
bot.OnNewMsg(func(bot *deltachat.Bot, accId deltachat.AccountId, msgId deltachat.MsgId) {
15+
msg, _ := bot.Rpc.GetMessage(accId, msgId)
16+
if msg.FromId > deltachat.ContactLastSpecial && msg.Text != "" {
17+
bot.Rpc.MiscSendTextMessage(accId, msg.ChatId, msg.Text)
18+
}
19+
})
20+
})
21+
cli.OnBotStart(func(cli *botcli.BotCli, bot *deltachat.Bot, cmd *cobra.Command, args []string) {
22+
cli.Logger.Info("OnBotStart event triggered: bot is about to start!")
23+
})
24+
cli.Start()
25+
}

go_deltabot_cli/go.mod

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module echobot
2+
3+
go 1.21.5
4+
5+
require (
6+
github.com/deltachat-bot/deltabot-cli-go v0.5.0
7+
github.com/deltachat/deltachat-rpc-client-go v1.127.0
8+
github.com/spf13/cobra v1.6.1
9+
)
10+
11+
require (
12+
github.com/creachadair/jrpc2 v1.0.0 // indirect
13+
github.com/creachadair/mds v0.0.1 // indirect
14+
github.com/inconshreveable/mousetrap v1.0.1 // indirect
15+
github.com/mdp/qrterminal/v3 v3.0.0 // indirect
16+
github.com/spf13/pflag v1.0.5 // indirect
17+
go.uber.org/atomic v1.7.0 // indirect
18+
go.uber.org/multierr v1.6.0 // indirect
19+
go.uber.org/zap v1.24.0 // indirect
20+
golang.org/x/sync v0.1.0 // indirect
21+
rsc.io/qr v0.2.0 // indirect
22+
)

go_deltabot_cli/go.sum

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
2+
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
3+
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
4+
github.com/creachadair/jrpc2 v1.0.0 h1:MJecUFNbda24o0Qa4CYru5NJvs6BEnmzupdAx3f7+98=
5+
github.com/creachadair/jrpc2 v1.0.0/go.mod h1:VNiDz7Qbua37RrefUJdMki9dVmsbrQPIQOPy907UvtE=
6+
github.com/creachadair/mds v0.0.1 h1:2nX6Sww4dXpScx3b6aYjH1n7iuEH715+jj+cKkKw9BY=
7+
github.com/creachadair/mds v0.0.1/go.mod h1:caBACU+n1Q/rZ252FTzfnG0/H+ZUi+UnIQtEOraMv/g=
8+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
10+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
11+
github.com/deltachat-bot/deltabot-cli-go v0.5.0 h1:WHHbG5++bO65risHzBj2jo0AOpBhJjVTKt6XH7d1KYo=
12+
github.com/deltachat-bot/deltabot-cli-go v0.5.0/go.mod h1:Lj4cmrHgOk0LKUOei5RAjx94VLTs11CfPhIqOBT+g8c=
13+
github.com/deltachat/deltachat-rpc-client-go v1.127.0 h1:fl0GAarlZsZBI3azYsBjGPV5kqZ9jxCVETyy2ONsCKI=
14+
github.com/deltachat/deltachat-rpc-client-go v1.127.0/go.mod h1:BAmhQofUS1dJltema3k1ACBMqw7lZCpm399P4ZX4IhY=
15+
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
16+
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
17+
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
18+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
19+
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
20+
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
21+
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
22+
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
23+
github.com/mdp/qrterminal v1.0.1/go.mod h1:Z33WhxQe9B6CdW37HaVqcRKzP+kByF3q/qLxOGe12xQ=
24+
github.com/mdp/qrterminal/v3 v3.0.0 h1:ywQqLRBXWTktytQNDKFjhAvoGkLVN3J2tAFZ0kMd9xQ=
25+
github.com/mdp/qrterminal/v3 v3.0.0/go.mod h1:NJpfAs7OAm77Dy8EkWrtE4aq+cE6McoLXlBqXQEwvE0=
26+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
27+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
28+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
29+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
30+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
31+
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
32+
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
33+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
34+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
35+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
36+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
37+
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
38+
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
39+
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
40+
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
41+
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
42+
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
43+
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
44+
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
45+
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
46+
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
47+
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
48+
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
49+
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
50+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
51+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
52+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
53+
rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY=
54+
rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs=

python_cffi/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Python (CFFI)
22

3-
> There are 3 alternative options available:
3+
> There are alternative options available:
44
>
55
> using the newer [jsonrpc based bindings](../python_jsonrpc)
66
>

python_deltabot_cli/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.venv
2+
/__pycache__

python_deltabot_cli/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Python deltabot-cli
2+
3+
This example is about creating a bot with the bot framework [deltabot-cli-py](https://github.com/deltachat-bot/deltabot-cli-py/), which gives a hook based interface and a cli interface to configure your bot.
4+
5+
> This is a python framework for bots, see [../README.md](../README.md) for other approaches to write bot in python.
6+
7+
## Usage
8+
9+
> Per default the bot data and configuration is stored in your user directory
10+
> (`Library/Application Support/bot_name/`, `.config/bot_name/`, on windows probably in `%APPDATA%` <!-- todo the location on windows needs to be checked -->).
11+
>
12+
> You can change configuration location with `--config-dir` flag (`--config-dir PATH` or `-c PATH`).
13+
14+
### Setup
15+
16+
#### Install
17+
18+
```sh
19+
# Optional create virtualenv
20+
pip install virtualenv
21+
virtualenv .venv
22+
source .venv/bin/activate
23+
24+
# install rpc server
25+
pip install deltachat-rpc-server
26+
27+
pip install deltabot-cli-py
28+
```
29+
30+
#### Configure
31+
32+
```sh
33+
python ./echobot.py init [email protected] password
34+
```
35+
36+
37+
### Start
38+
39+
```sh
40+
python ./echobot.py serve
41+
```

python_deltabot_cli/echobot.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
"""Minimal echo-bot example."""
3+
4+
import logging
5+
6+
from deltabot_cli import BotCli, events
7+
8+
cli = BotCli("echobot")
9+
10+
11+
@cli.on(events.RawEvent)
12+
def log_event(event):
13+
logging.info(event)
14+
15+
16+
@cli.on(events.NewMessage)
17+
def echo(event):
18+
msg = event.message_snapshot
19+
msg.chat.send_text(msg.text)
20+
21+
22+
if __name__ == "__main__":
23+
cli.start()

python_jsonrpc/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Python (CFFI)
22

3-
> There are 3 alternative options available:
3+
> There are alternative options available:
44
>
55
> using the older legacy [cffi based bindings](../python_cffi)
66
>
77
> frameworks:
88
> - [using deltabot](../python_deltabot_plugin) (bot framework, includes features as chat command parsing)
99
> - [using simplebot](../python_simplebot_plugin) (simplebot is a maintained fork of deltabot with many plugins availible)
10+
> - [using deltabot-cli](../python_deltabot_cli)
1011
1112
## Installation
1213

0 commit comments

Comments
 (0)