icqbotapi

package module
v0.0.0-...-53cc220 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2020 License: MIT Imports: 16 Imported by: 0

README

Golang bindings for the ICQ Bot API

GoDoc Go Report Card Pure Go implementation of bindings to the ICQ Bot API

Documentation

Index

Examples

Constants

View Source
const (
	APITypeICQ apiType = iota
	APITypeAgent
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Admin

type Admin struct {
	UserID    string
	IsCreator bool
}

Admin represents chat administrator.

func (Admin) MarshalEasyJSON

func (v Admin) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Admin) MarshalJSON

func (v Admin) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Admin) UnmarshalEasyJSON

func (v *Admin) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Admin) UnmarshalJSON

func (v *Admin) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Bot

type Bot struct {
	// contains filtered or unexported fields
}

func New

func New(token string, client *http.Client, t apiType) *Bot

New creates new instance of Bot

Example
const token = "001.1104030426.1757333006:757143498"
bot := New(token, http.DefaultClient, APITypeICQ)
_ = bot
Output:

func (*Bot) DeleteMessage

func (b *Bot) DeleteMessage(ctx context.Context, r *DeleteMessageRequest) (*StatusResponse, error)

EditMessage provides the function of deleting messages.

Example
const token = "001.1104030426.1757333006:757143498"
bot := New(token, http.DefaultClient, APITypeICQ)

req := &DeleteMessageRequest{
	ChatID:    "chat1",
	MessageID: "6724275801631490259",
}

resp, _ := bot.DeleteMessage(context.Background(), req)

log.Printf("%#v", resp)
Output:

func (*Bot) EditMessage

func (b *Bot) EditMessage(ctx context.Context, r *EditMessageRequest) (*StatusMessageIDResponse, error)

EditMessage provides the function of editing messages.

Example
const token = "001.1104030426.1757333006:757143498"
bot := New(token, http.DefaultClient, APITypeICQ)

req := &EditMessageRequest{
	ChatID:    "chat1",
	MessageID: "6724288965706252425",
	Text:      "kek",
}

resp, _ := bot.EditMessage(context.Background(), req)

log.Printf("%#v", resp)
Output:

func (*Bot) GetChatAdmins

func (b *Bot) GetChatAdmins(ctx context.Context, r ChatID) (*GetAdminsResponse, error)

GetChatAdmins provides a function to obtain information about the chat administration.

Example
const token = "001.1104030426.1757333006:757143498"
bot := New(token, http.DefaultClient, APITypeICQ)

data, _ := bot.GetChatAdmins(context.Background(), "chat1")

log.Printf("%#v", data)
Output:

func (*Bot) GetChatInfo

func (b *Bot) GetChatInfo(ctx context.Context, r ChatID) (*ChatInfoResponse, error)

GetChatInfo returns information about chat.

Example
const token = "001.1104030426.1757333006:757143498"
bot := New(token, http.DefaultClient, APITypeICQ)
chatInfo, _ := bot.GetChatInfo(context.Background(), "chat1")

log.Printf("%#v", chatInfo)
Output:

func (*Bot) GetFileInfo

func (b *Bot) GetFileInfo(ctx context.Context, r FileID) (*FileInfoResponse, error)

GetFileInfo provides the file information function.

Example
const token = "001.1104030426.1757333006:757143498"
bot := New(token, http.DefaultClient, APITypeICQ)

data, _ := bot.GetFileInfo(context.Background(), "05j5Lk9Oka1VBpeMLS7Qv35d5189ac1af")

log.Printf("%#v", data)
Output:

func (*Bot) GetSelf

func (b *Bot) GetSelf(ctx context.Context) (*GetSelfResponse, error)

GetSelf returns information about Bot. It can be used to validate API token.

Example
const token = "001.1104030426.1757333006:757143498"
bot := New(token, http.DefaultClient, APITypeICQ)

data, _ := bot.GetSelf(context.Background())

log.Printf("%#v", data)
Output:

func (*Bot) HandleEvents

func (b *Bot) HandleEvents(ctx context.Context)
Example
const token = "001.1104030426.1757333006:757143498"
bot := New(token, http.DefaultClient, APITypeICQ)

bot.SetNewMessageHandler(func(e event.NewMessagePayload) {
	log.Printf("%#v", e)
})

bot.SetErrorHandler(func(err error) {
	log.Print(err)
})

ctx, cancel := context.WithCancel(context.Background())
bot.HandleEvents(ctx)
time.Sleep(time.Second * 3)
cancel()
Output:

func (*Bot) PollEvents

func (b *Bot) PollEvents(ctx context.Context) <-chan event.Event
Example
const token = "001.1104030426.1757333006:757143498"
bot := New(token, http.DefaultClient, APITypeICQ)

for event := range bot.PollEvents(context.Background()) {
	log.Printf("%#v", event)
}
Output:

func (*Bot) SendChatActions

func (b *Bot) SendChatActions(ctx context.Context, reqs <-chan ChatActionsRequest)

SendChatActions provides a function to sent actions to chat.

Example
const token = "001.1104030426.1757333006:757143498"
bot := New(token, http.DefaultClient, APITypeICQ)
events := make(chan ChatActionsRequest)

bot.SendChatActions(context.Background(), events)

chats := []ChatID{
	"chat1",
	"chat2",
	"chat3",
}

for i := 0; i < 50; i++ {
	events <- ChatActionsRequest{
		ChatID: chats[i%len(chats)],
		Actions: []ChatAction{
			ChatActionTyping,
		},
	}

	time.Sleep(time.Millisecond * 100)
}

close(events)
Output:

func (*Bot) SendFile

SendFile provides the function of sending text messages with already downloaded file attachments.

Example
const token = "001.1104030426.1757333006:757143498"
bot := New(token, http.DefaultClient, APITypeICQ)

req := &SendFileRequest{
	fileRequest: fileRequest{
		SendTextRequest: SendTextRequest{
			ChatID: "chat1",
			Text:   "is's pepe",
		},
		Caption: "it's pepe",
	},
	FileID: "05j5L69UrfAdj8tZCGyi8H5d5160d61af",
}

resp, _ := bot.SendFile(context.Background(), req)

log.Printf("%#v", resp)
Output:

func (*Bot) SendNewFile

func (b *Bot) SendNewFile(ctx context.Context, r *SendNewFileRequest) (*SendNewFileResponse, error)

SendNewFile provides the function of sending text messages with file attachments.

Example
const token = "001.1104030426.1757333006:757143498"
bot := New(token, http.DefaultClient, APITypeICQ)

f, err := os.Open("./pepe.jpg")
if err != nil {
	panic(err)
}

defer f.Close()

req := &SendNewFileRequest{
	fileRequest: fileRequest{
		SendTextRequest: SendTextRequest{
			ChatID: "chat1",
			Text:   "is's pepe",
		},
		Caption: "it's pepe",
	},
	File:     f,
	Filename: "pepe.jpg",
}

resp, _ := bot.SendNewFile(context.Background(), req)

log.Printf("%#v", resp)
Output:

func (*Bot) SendText

SendText performs plain text message function.

Example
const token = "001.1104030426.1757333006:757143498"
bot := New(token, http.DefaultClient, APITypeICQ)

req := &SendTextRequest{
	ChatID: "chat1",
	Text:   "kek",
}

resp, _ := bot.SendText(context.Background(), req)

log.Printf("%+v", resp)
Output:

func (*Bot) SetDeleteMessageHandler

func (b *Bot) SetDeleteMessageHandler(fn deleteMessageHandlerFunc)

sets the handler to events about delete message.

func (*Bot) SetEditMessageHandler

func (b *Bot) SetEditMessageHandler(fn editMessageHandlerFunc)

SetEditMessageHandler sets the handler to events about edit message.

func (*Bot) SetErrorHandler

func (b *Bot) SetErrorHandler(fn errorHandlerFunc)

SetErrorHandler sets the processing errors handler.

func (*Bot) SetLeftChatMemberHandler

func (b *Bot) SetLeftChatMemberHandler(fn leftChatMembersHandlerFunc)

SetLeftChatMemberHandler sets the handler to events about left chat member.

func (*Bot) SetNewChatMemberHandler

func (b *Bot) SetNewChatMemberHandler(fn newChatMembersHandlerFunc)

SetNewChatMemberHandler sets the handler to events about new chat member.

func (*Bot) SetNewMessageHandler

func (b *Bot) SetNewMessageHandler(fn newMessageHandlerFunc)

SetNewMessageHandler sets the handler to events about new message.

func (*Bot) SetPinMessageHandler

func (b *Bot) SetPinMessageHandler(fn pinMessageHandlerFunc)

sets the handler to events about pin message.

func (*Bot) SetUnpinMessageHandler

func (b *Bot) SetUnpinMessageHandler(fn unpinMessageHandlerFunc)

SetUnpinMessageHandler sets the handler to events about unpin message.

type ChatAction

type ChatAction string

ChatAction represents actions which can be in chats.

const (
	ChatActionTyping  ChatAction = "typing"
	ChatActionLooking ChatAction = "looking"
)

type ChatActionsRequest

type ChatActionsRequest struct {
	ChatID  ChatID
	Actions []ChatAction
}

ChatActionsRequest represents container to sent actions to chat.

func (ChatActionsRequest) MarshalEasyJSON

func (v ChatActionsRequest) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (ChatActionsRequest) MarshalJSON

func (v ChatActionsRequest) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*ChatActionsRequest) UnmarshalEasyJSON

func (v *ChatActionsRequest) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*ChatActionsRequest) UnmarshalJSON

func (v *ChatActionsRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type ChatID

type ChatID string

ChatID represents chat identifier.

type ChatInfoResponse

type ChatInfoResponse struct {
	StatusResponse
	InviteLink url.URL `json:"inviteLink"`
	IsPublic   bool    `json:"public"`
	Title      string  `json:"title"`
	Group      string  `json:"group"`
}

ChatInfoResponse represents chat properties.

func (ChatInfoResponse) MarshalEasyJSON

func (v ChatInfoResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (ChatInfoResponse) MarshalJSON

func (v ChatInfoResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*ChatInfoResponse) UnmarshalEasyJSON

func (v *ChatInfoResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*ChatInfoResponse) UnmarshalJSON

func (v *ChatInfoResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type DeleteMessageRequest

type DeleteMessageRequest struct {
	ChatID    string `json:"chatId"`
	MessageID string `json:"msgId"`
}

DeleteMessageRequest represents data for deleting a messages.

func (DeleteMessageRequest) MarshalEasyJSON

func (v DeleteMessageRequest) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (DeleteMessageRequest) MarshalJSON

func (v DeleteMessageRequest) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*DeleteMessageRequest) UnmarshalEasyJSON

func (v *DeleteMessageRequest) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*DeleteMessageRequest) UnmarshalJSON

func (v *DeleteMessageRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type EditMessageRequest

type EditMessageRequest struct {
	ChatID    string `json:"chatId"`
	MessageID string `json:"msgId"`
	Text      string `json:"text"`
}

EditMessageRequest represents data for editing a messages.

func (EditMessageRequest) MarshalEasyJSON

func (v EditMessageRequest) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (EditMessageRequest) MarshalJSON

func (v EditMessageRequest) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*EditMessageRequest) UnmarshalEasyJSON

func (v *EditMessageRequest) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*EditMessageRequest) UnmarshalJSON

func (v *EditMessageRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type FileID

type FileID string

FileID represents file identifier.

type FileInfoResponse

type FileInfoResponse struct {
	StatusResponse
	Type     string `json:"type"`
	Size     uint64 `json:"size"`
	Filename string `json:"filename"`
	URL      string `json:"url"`
}

FileInfoResponse represents info about uploaded file.

func (FileInfoResponse) MarshalEasyJSON

func (v FileInfoResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (FileInfoResponse) MarshalJSON

func (v FileInfoResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*FileInfoResponse) UnmarshalEasyJSON

func (v *FileInfoResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*FileInfoResponse) UnmarshalJSON

func (v *FileInfoResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type GetAdminsResponse

type GetAdminsResponse struct {
	StatusResponse
	Admins []Admin
}

GetAdminsResponse represents information about chat administration.

func (GetAdminsResponse) MarshalEasyJSON

func (v GetAdminsResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (GetAdminsResponse) MarshalJSON

func (v GetAdminsResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*GetAdminsResponse) UnmarshalEasyJSON

func (v *GetAdminsResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*GetAdminsResponse) UnmarshalJSON

func (v *GetAdminsResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type GetSelfResponse

type GetSelfResponse struct {
	UserID    string `json:"userId"`
	Nick      string `json:"nick"`
	FirstName string `json:"firstName"`
	About     string `json:"about"`
	Photo     []struct {
		URL string `json:"url"`
	} `json:"photo"`
	Ok bool `json:"ok"`
}

GetSelfResponse represents info about self.

func (GetSelfResponse) MarshalEasyJSON

func (v GetSelfResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (GetSelfResponse) MarshalJSON

func (v GetSelfResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*GetSelfResponse) UnmarshalEasyJSON

func (v *GetSelfResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*GetSelfResponse) UnmarshalJSON

func (v *GetSelfResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type PollResponse

type PollResponse struct {
	Events []event.Event `json:"events"`
}

func (PollResponse) MarshalEasyJSON

func (v PollResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (PollResponse) MarshalJSON

func (v PollResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*PollResponse) UnmarshalEasyJSON

func (v *PollResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*PollResponse) UnmarshalJSON

func (v *PollResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type SendFileRequest

type SendFileRequest struct {
	FileID string
	// contains filtered or unexported fields
}

SendFileRequest presents request with plain text with attached existing file/voice.

type SendNewFileRequest

type SendNewFileRequest struct {
	File     io.Reader
	Filename string
	// contains filtered or unexported fields
}

SendNewFileRequest presents request with plain text with attached new file/voice.

type SendNewFileResponse

type SendNewFileResponse struct {
	StatusMessageIDResponse
	FileID string `json:"fileId"`
}

SendNewFileResponse contains information about sent message with attached files.

func (SendNewFileResponse) MarshalEasyJSON

func (v SendNewFileResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (SendNewFileResponse) MarshalJSON

func (v SendNewFileResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*SendNewFileResponse) UnmarshalEasyJSON

func (v *SendNewFileResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*SendNewFileResponse) UnmarshalJSON

func (v *SendNewFileResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type SendTextRequest

type SendTextRequest struct {
	ChatID           string
	Text             string
	ReplyMessageID   uint64
	ForwardChatID    string
	ForwardMessageID uint64
}

SendSendTextRequest represents plain text interaction request.

type StatusMessageIDResponse

type StatusMessageIDResponse struct {
	StatusResponse
	MessageID string `json:"msgId"`
}

StatusMessageIDResponse represents response status data for requests which deal with messages.

func (StatusMessageIDResponse) MarshalEasyJSON

func (v StatusMessageIDResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (StatusMessageIDResponse) MarshalJSON

func (v StatusMessageIDResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*StatusMessageIDResponse) UnmarshalEasyJSON

func (v *StatusMessageIDResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*StatusMessageIDResponse) UnmarshalJSON

func (v *StatusMessageIDResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type StatusResponse

type StatusResponse struct {
	Ok          bool       `json:"ok"`
	Description opt.String `json:"description"`
}

StatusResponse represents common response status data.

func (StatusResponse) MarshalEasyJSON

func (v StatusResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (StatusResponse) MarshalJSON

func (v StatusResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*StatusResponse) UnmarshalEasyJSON

func (v *StatusResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*StatusResponse) UnmarshalJSON

func (v *StatusResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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