Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ name: CI
on:
push:
branches: [ "master", "main" ]
paths:
- "examples/**"
- "scripts/**"
- "v2/**"
pull_request:
branches: [ "master", "main" ]
paths:
- "examples/**"
- "scripts/**"
- "v2/**"

jobs:

build:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
Expand All @@ -23,7 +31,6 @@ jobs:
- name: Test
run: |
export TEST_DEBUG=1
export TEST_EXTRA_TAGS=" "
bash ./scripts/run_tests.sh

- name: Coverage Badge - Generate
Expand Down Expand Up @@ -58,12 +65,3 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.head_ref }}

services:
mail_server:
image: ghcr.io/deltachat/mail-server-tester:release
ports:
- 3025:25
- 3143:143
- 3465:465
- 3993:993
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
*~
*.out
*.out
accounts/
examples/*/executable*
examples/*/go.sum
38 changes: 0 additions & 38 deletions CHANGELOG.md

This file was deleted.

24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Contributing

After doing your modifications make sure all tests pass, and add tests to ensure
code coverage of your new modifications.

### Running the test suite

To run the integration tests run:

```
./scripts/run_tests.sh
```

The `run_tests.sh` script will install `deltachat-rpc-server` (if needed)
and run all tests.

### Updating dependencies

```
cd v2
go get -u ./...
```

To update the `deltachat-rpc-server` program in CI, update `scripts/run_tests.sh`
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ creating the bot CLI.
## Install

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

### Installing deltachat-rpc-server
Expand All @@ -28,8 +28,8 @@ https://github.com/chatmail/core/tree/main/deltachat-rpc-server

Example echo-bot written with deltabot-cli:

<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./examples/echobot.go) -->
<!-- The below code snippet is automatically added from ./examples/echobot.go -->
<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./examples/echobot/echobot.go) -->
<!-- The below code snippet is automatically added from ./examples/echobot/echobot.go -->
```go
package main

Expand Down Expand Up @@ -69,14 +69,7 @@ go run ./echobot.go serve

Use `go run ./echobot.go --help` to see all the available options.

Check the [examples folder](https://github.com/deltachat-bot/deltabot-cli-go/tree/master/examples) for
more examples.
Check the [examples folder](./examples) 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.

## 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
13 changes: 7 additions & 6 deletions examples/echobot.go → examples/echobot/echobot.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package main

import (
"github.com/chatmail/rpc-client-go/deltachat"
"github.com/deltachat-bot/deltabot-cli-go/botcli"
"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")

// 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) {
// 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.MiscSendTextMessage(accId, msg.ChatId, 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()

_ = cli.Start()
}
19 changes: 19 additions & 0 deletions examples/echobot/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module executable

go 1.25.1

require (
github.com/chatmail/rpc-client-go/v2 v2.0.1
github.com/deltachat-bot/deltabot-cli-go/v2 v2.0.0-00010101000000-000000000000
github.com/spf13/cobra v1.10.2
)

require (
github.com/creachadair/jrpc2 v1.1.2 // indirect
github.com/creachadair/mds v0.8.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.9 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/sync v0.6.0 // indirect
)
Empty file removed examples/go.mod
Empty file.
19 changes: 19 additions & 0 deletions examples/infobot/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module executable

go 1.25.1

require (
github.com/chatmail/rpc-client-go/v2 v2.0.1
github.com/deltachat-bot/deltabot-cli-go/v2 v2.0.0-00010101000000-000000000000
github.com/spf13/cobra v1.10.2
)

require (
github.com/creachadair/jrpc2 v1.1.2 // indirect
github.com/creachadair/mds v0.8.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.9 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/sync v0.6.0 // indirect
)
40 changes: 18 additions & 22 deletions examples/infobot.go → examples/infobot/infobot.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
// This example demonstrates how to create bots that have administrators.
//
// The bot has the /info command that can only be executed by bot administrators in the admins chat.
// To become admin you must use the `admin` subcommand in the cli, and scan the QR that will be shown.
// The bot has the /info command that can only be executed by bot administrators (members of the admins chat).
// To become admin you must use the `admin` subcommand in the cli, and open the invite link that will be shown.
package main

import (
"fmt"

"github.com/chatmail/rpc-client-go/deltachat"
"github.com/deltachat-bot/deltabot-cli-go/botcli"
"github.com/chatmail/rpc-client-go/v2/deltachat"
"github.com/deltachat-bot/deltabot-cli-go/v2/botcli"
"github.com/spf13/cobra"
)

var cli *botcli.BotCli = botcli.New("infobot")

// Process messages sent to the group of administrators and allow to run privileged commands there.
func onNewMsg(bot *deltachat.Bot, accId deltachat.AccountId, msgId deltachat.MsgId) {
// Process messages sent by administrators.
func onNewMsg(bot *deltachat.Bot, accId uint32, msgId uint32) {
msg, _ := bot.Rpc.GetMessage(accId, msgId)
if msg.FromId <= deltachat.ContactLastSpecial { // ignore message from self
return
}

adminChatId, _ := cli.AdminChat(bot, accId)
if msg.ChatId == adminChatId {
isAdmin, _ := cli.IsAdmin(bot, accId, msg.FromId)
if isAdmin {
switch msg.Text {
case "/info":
info, _ := bot.Rpc.GetInfo(accId)
var text string
for key, value := range info {
text += key + "=" + value + "\n"
}
bot.Rpc.MiscSendTextMessage(accId, msg.ChatId, text)
isAdmin, _ := cli.IsAdmin(bot, accId, msg.FromId)
if isAdmin {
switch msg.Text {
case "/info":
info, _ := bot.Rpc.GetInfo(accId)
var text string
for key, value := range info {
text += key + "=" + value + "\n"
}
_, _ = bot.Rpc.SendMsg(accId, msg.ChatId, deltachat.MessageData{Text: &text})
}
}
}
Expand All @@ -47,11 +44,10 @@ func main() {
}
cli.AddCommand(infoCmd, func(cli *botcli.BotCli, bot *deltachat.Bot, cmd *cobra.Command, args []string) {
var info map[string]string
if cli.SelectedAddr == "" { // no account selected with --a/--account, show system info
if cli.SelectedAccount == 0 { // no account selected with --a/--account, show system info
info, _ = bot.Rpc.GetSystemInfo()
} else { // account selected, show info about that account
accId, _ := cli.GetAccount(bot.Rpc, cli.SelectedAddr)
info, _ = bot.Rpc.GetInfo(accId)
info, _ = bot.Rpc.GetInfo(cli.SelectedAccount)
}
for key, val := range info {
fmt.Printf("%v=%#v\n", key, val)
Expand All @@ -61,5 +57,5 @@ func main() {
cli.OnBotInit(func(cli *botcli.BotCli, bot *deltachat.Bot, cmd *cobra.Command, args []string) {
bot.OnNewMsg(onNewMsg)
})
cli.Start()
_ = cli.Start()
}
36 changes: 36 additions & 0 deletions examples/webxdcbot/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
RPC API definitions.

Here you can define functions that can be called on the mini-app side.

```
webxdc.sendUpdate({payload: {id: "1", method: "Noop", params: []}}, "");
```
*/
package main

import (
"github.com/deltachat-bot/deltabot-cli-go/v2/xdcrpc"
)

// You must put your available RPC API in a custom type
type API struct{}

// Function without arguments or return value
func (api *API) Noop() {
// do nothing
}

// Function with return value but no *xdcrpc.Error
func (api *API) Echo(text string) string {
return text
}

// Function that might return an xdcrpc.Error.
// Functions must return `*xdcrpc.Error` instead of `error`
func (api *API) Divide(a int, b int) (int, *xdcrpc.Error) {
if b == 0 {
return 0, &xdcrpc.Error{Code: 1, Message: "Division by zero"}
}
return a / b, nil
}
19 changes: 19 additions & 0 deletions examples/webxdcbot/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module executable

go 1.25.1

require (
github.com/chatmail/rpc-client-go/v2 v2.0.1
github.com/deltachat-bot/deltabot-cli-go/v2 v2.0.0-00010101000000-000000000000
github.com/spf13/cobra v1.10.2
)

require (
github.com/creachadair/jrpc2 v1.1.2 // indirect
github.com/creachadair/mds v0.8.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.9 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/sync v0.6.0 // indirect
)
Loading
Loading