seatalkbot

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 12 Imported by: 0

README

seatalkbot

Seatalk Bot Client to call https://openapi.seatalk.io APIs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// SendPrivateMessage send a private message to a user by employeeCode.
	SendPrivateMessage(ctx context.Context, employeeCode string, message Message) error

	// GetGroupIDs get list of group ids joined by the bot.
	GetGroupIDs(ctx context.Context) ([]string, error)
	// SendGroupMessage send a message to a group by groupID.
	SendGroupMessage(ctx context.Context, groupID string, message Message) (messageID string, err error)

	// UpdateAccessToken gets new access token by using the credentials and store it in the client.
	UpdateAccessToken(ctx context.Context) error
	// AccessToken gets the underlying access token inside the client.
	// It might be used to implement your own API caller that's not yet supported by this library.
	AccessToken() string

	// Close stops the goroutines that auto refresh the access token. It is required to call
	// this function before the object passes out of scope, as it will otherwise leak memory.
	Close() error
}

Client is a Seatalkbot API caller. Client must initialize access token and update it with a new one before expired. You MUST call Close() on a client to avoid leaks, it will not be garbage-collected automatically when it passes out of scope. It is safe to share a client amongst many users.

func NewClient

func NewClient(config Config) (Client, error)

NewClient returns a Client with the provided *http.Client and bot credentials. It will initialize access token using the credentials and automatically refresh the access token every 7000 seconds (expiration is 7200 seconds). It is required to call Close() before the object passes out of scope, as it will otherwise leak memory.

type Config

type Config struct {
	// HTTPClient will be used for every HTTP calls made by the seatalkbot client.
	HTTPClient *http.Client
	// Host is the url of the bot api. It's https://openapi.seatalk.io by default.
	Host string
	// AppID of the seatalk bot. It can be found in the app setting at the seatalk dashboard.
	AppID string
	// AppSecret of the seatalk bot. It can be found in the app setting at the seatalk dashboard.
	AppSecret string
}

type Message

type Message interface {
	Message() json.RawMessage
}

Message is used as a parameter for sending message

func TextMessage

func TextMessage(content, quotedMessageID string) Message

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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