Skip to content
Open
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
5 changes: 5 additions & 0 deletions deltachat/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ func (rpc *Rpc) SetConfig(accountId AccountId, key string, value option.Option[s
return rpc.Transport.Call(rpc.Context, "set_config", accountId, key, value)
}

// Set account configuration value from qr code
func (rpc *Rpc) SetConfigFromQr(accountId AccountId, qrContent string) error {
return rpc.Transport.Call(rpc.Context, "set_config_from_qr", accountId, qrContent)
}

// Tweak several account configuration values in a batch.
func (rpc *Rpc) BatchSetConfig(accountId AccountId, config map[string]option.Option[string]) error {
return rpc.Transport.Call(rpc.Context, "batch_set_config", accountId, config)
Expand Down
1 change: 1 addition & 0 deletions examples/basic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
accounts
10 changes: 10 additions & 0 deletions examples/basic/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Basic Examples


```sh
go run echobot.go DCACCOUNT:https://nine.testrun.org/new
```

```sh
go run client.go DCACCOUNT:https://nine.testrun.org/new
```
9 changes: 3 additions & 6 deletions examples/client.go → examples/basic/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,16 @@ func main() {
rpc.StartIo(accId)
} else {
log.Println("Account not configured, configuring...")
rpc.BatchSetConfig(accId,
map[string]option.Option[string]{
"addr": option.Some(os.Args[1]),
"mail_pw": option.Some(os.Args[2]),
},
)
rpc.SetConfigFromQr(accId, os.Args[1])
if err := rpc.Configure(accId); err != nil {
log.Fatalln(err)
}
}

addr, _ := rpc.GetConfig(accId, "addr")
log.Println("Using account:", addr.Unwrap())
inviteLink, _ := rpc.GetChatSecurejoinQrCode(accId, option.None[deltachat.ChatId]())
log.Println("Listening on:", inviteLink)

for {
accId2, event, err := rpc.GetNextEvent()
Expand Down
8 changes: 5 additions & 3 deletions examples/echobot.go → examples/basic/echobot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/chatmail/rpc-client-go/deltachat"
"github.com/chatmail/rpc-client-go/deltachat/option"
"github.com/chatmail/rpc-client-go/deltachat/transport"
)

Expand Down Expand Up @@ -44,13 +45,14 @@ func main() {

if isConf, _ := bot.Rpc.IsConfigured(accId); !isConf {
log.Println("Bot not configured, configuring...")
err := bot.Configure(accId, os.Args[1], os.Args[2])
rpc.SetConfigFromQr(accId, os.Args[1])
err := bot.Rpc.Configure(accId)
if err != nil {
log.Fatalln(err)
}
}

addr, _ := bot.Rpc.GetConfig(accId, "configured_addr")
log.Println("Listening at:", addr.Unwrap())
inviteLink, _ := bot.Rpc.GetChatSecurejoinQrCode(accId, option.None[deltachat.ChatId]())
log.Println("Listening at:", inviteLink)
bot.Run()
}
13 changes: 13 additions & 0 deletions examples/basic/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module echobot

go 1.25.1

replace github.com/chatmail/rpc-client-go => ../../

require github.com/chatmail/rpc-client-go v0.0.0-00010101000000-000000000000

require (
github.com/creachadair/jrpc2 v1.1.2 // indirect
github.com/creachadair/mds v0.8.2 // indirect
golang.org/x/sync v0.6.0 // indirect
)
18 changes: 18 additions & 0 deletions examples/basic/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
github.com/creachadair/jrpc2 v1.1.2 h1:UOYMipEFYlwd5qmcvs9GZBurn3oXt1UDIX5JLjWWFzo=
github.com/creachadair/jrpc2 v1.1.2/go.mod h1:JcCe2Eny3lIvVwZLm92WXyU+tNUgTBWFCLMsfNkjEGk=
github.com/creachadair/mds v0.8.2 h1:+Jvq8XBrREerXI/QZpNAeiLjIBuVMOl8p3v+mKgSexY=
github.com/creachadair/mds v0.8.2/go.mod h1:4vrFYUzTXMJpMBU+OA292I6IUxKWCCfZkgXg+/kBZMo=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Empty file removed examples/go.mod
Empty file.