deltachat-rpc-client-go

module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2023 License: MPL-2.0

README

Delta Chat API for Go

CI Go version

Delta Chat client & bot API for Golang.

Install

go get -u github.com/deltachat/deltachat-rpc-client-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. To install it run:

cargo install --git https://github.com/deltachat/deltachat-core-rust/ deltachat-rpc-server

For more info check: https://github.com/deltachat/deltachat-core-rust/tree/master/deltachat-rpc-server

Usage

Example echo-bot that will echo back any text message you send to it:

package main

import (
    "github.com/deltachat/deltachat-rpc-client-go/deltachat"
    "log"
    "os"
)

func main() {
    rpc := deltachat.NewRpcIO()
    defer rpc.Stop()
    rpc.Start()

    bot := deltachat.NewBotFromAccountManager(&deltachat.AccountManager{rpc})
    bot.OnNewMsg(func(msg *deltachat.Message) {
        snapshot, _ := msg.Snapshot()
        chat := deltachat.Chat{bot.Account, snapshot.ChatId}
        chat.SendText(snapshot.Text)
    })

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

    addr, _ := bot.GetConfig("addr")
    log.Println("Listening at:", addr)
    bot.RunForever()
}

Save the previous code snippet as echobot.go then run:

go run ./echobot.go bot@example.com PASSWORD

Check the examples folder for more examples.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL