xdcrpc

package
v1.134.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MPL-2.0 Imports: 4 Imported by: 2

Documentation

Overview

Package helping with the communication between bots and WebXDC apps via JSON-RPC 1.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUpdate

func GetUpdate(rpc *deltachat.Rpc, accId deltachat.AccountId, msgId deltachat.MsgId, serial uint) (json.RawMessage, error)

Get the status update with the given serial

func GetUpdates

func GetUpdates(rpc *deltachat.Rpc, accId deltachat.AccountId, msgId deltachat.MsgId, serial uint) ([]json.RawMessage, error)

Get all setatus updates with serial greater than the given serial

func HandleMessage

func HandleMessage(rpc *deltachat.Rpc, accId deltachat.AccountId, msgId deltachat.MsgId, serial uint, api any) error

func IsFromSelf

func IsFromSelf(rawUpdate []byte) bool

Return true if the raw status update is from self, false otherwise

func SendPayload

func SendPayload[T any](rpc *deltachat.Rpc, accId deltachat.AccountId, msgId deltachat.MsgId, payload T) error

Send a WebXDC status update with the given payload

func SendUpdate

func SendUpdate[T any](rpc *deltachat.Rpc, accId deltachat.AccountId, msgId deltachat.MsgId, update StatusUpdate[T], description string) error

Send a WebXDC status update

Types

type Error

type Error struct {
	Code    ErrorCode `json:"code,omitempty"`
	Message string    `json:"message,omitempty"`
	Data    any       `json:"data,omitempty"`
}

Error data sent by the bot in ErrorResponse

type ErrorCode

type ErrorCode int
const (
	// The method does not exist / is not available
	MethodNotFoud ErrorCode = -32601
	// Invalid JSON was received by the server
	ParseError ErrorCode = -32700
	// The JSON sent is not a valid Request object
	InvalidRequest ErrorCode = -32600
	// Invalid method parameter(s)
	InvalidParams ErrorCode = -32602
)

type Request

type Request struct {
	Id     string `json:"id,omitempty"`
	Method string `json:"method"`
	Params []any  `json:"params"`
}

Request sent by the frontend app

type Response

type Response struct {
	Id     string `json:"id,omitempty"`
	Result any    `json:"result"`
	Error  *Error `json:"error"`
}

Response sent by the bot

func GetResponse

func GetResponse(api any, rawUpdate []byte) *Response

type SelfMessageErr

type SelfMessageErr struct {
}

func (*SelfMessageErr) Error

func (self *SelfMessageErr) Error() string

type StatusUpdate

type StatusUpdate[T any] struct {
	Info      string `json:"info,omitempty"`
	Summary   string `json:"summary,omitempty"`
	Document  string `json:"document,omitempty"`
	Payload   T      `json:"payload,omitempty"`
	Serial    uint   `json:"serial,omitempty"`
	MaxSerial uint   `json:"max_serial,omitempty"`
}

Jump to

Keyboard shortcuts

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