Documentation
¶
Index ¶
- Constants
- type Admin
- type Bot
- func (b *Bot) DeleteMessage(ctx context.Context, r *DeleteMessageRequest) (*StatusResponse, error)
- func (b *Bot) EditMessage(ctx context.Context, r *EditMessageRequest) (*StatusMessageIDResponse, error)
- func (b *Bot) GetChatAdmins(ctx context.Context, r ChatID) (*GetAdminsResponse, error)
- func (b *Bot) GetChatInfo(ctx context.Context, r ChatID) (*ChatInfoResponse, error)
- func (b *Bot) GetFileInfo(ctx context.Context, r FileID) (*FileInfoResponse, error)
- func (b *Bot) GetSelf(ctx context.Context) (*GetSelfResponse, error)
- func (b *Bot) HandleEvents(ctx context.Context)
- func (b *Bot) PollEvents(ctx context.Context) <-chan event.Event
- func (b *Bot) SendChatActions(ctx context.Context, reqs <-chan ChatActionsRequest)
- func (b *Bot) SendFile(ctx context.Context, r *SendFileRequest) (*StatusMessageIDResponse, error)
- func (b *Bot) SendNewFile(ctx context.Context, r *SendNewFileRequest) (*SendNewFileResponse, error)
- func (b *Bot) SendText(ctx context.Context, r *SendTextRequest) (*StatusMessageIDResponse, error)
- func (b *Bot) SetDeleteMessageHandler(fn deleteMessageHandlerFunc)
- func (b *Bot) SetEditMessageHandler(fn editMessageHandlerFunc)
- func (b *Bot) SetErrorHandler(fn errorHandlerFunc)
- func (b *Bot) SetLeftChatMemberHandler(fn leftChatMembersHandlerFunc)
- func (b *Bot) SetNewChatMemberHandler(fn newChatMembersHandlerFunc)
- func (b *Bot) SetNewMessageHandler(fn newMessageHandlerFunc)
- func (b *Bot) SetPinMessageHandler(fn pinMessageHandlerFunc)
- func (b *Bot) SetUnpinMessageHandler(fn unpinMessageHandlerFunc)
- type ChatAction
- type ChatActionsRequest
- type ChatID
- type ChatInfoResponse
- type DeleteMessageRequest
- type EditMessageRequest
- type FileID
- type FileInfoResponse
- type GetAdminsResponse
- type GetSelfResponse
- type PollResponse
- type SendFileRequest
- type SendNewFileRequest
- type SendNewFileResponse
- type SendTextRequest
- type StatusMessageIDResponse
- type StatusResponse
Examples ¶
Constants ¶
const ( APITypeICQ apiType = iota APITypeAgent )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Admin ¶
Admin represents chat administrator.
func (Admin) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Admin) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Admin) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Admin) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
func New ¶
New creates new instance of Bot
Example ¶
const token = "001.1104030426.1757333006:757143498" bot := New(token, http.DefaultClient, APITypeICQ) _ = bot
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)
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)
func (*Bot) GetChatAdmins ¶
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)
func (*Bot) GetChatInfo ¶
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)
func (*Bot) GetFileInfo ¶
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)
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)
func (*Bot) HandleEvents ¶
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()
func (*Bot) PollEvents ¶
Example ¶
const token = "001.1104030426.1757333006:757143498"
bot := New(token, http.DefaultClient, APITypeICQ)
for event := range bot.PollEvents(context.Background()) {
log.Printf("%#v", event)
}
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)
func (*Bot) SendFile ¶
func (b *Bot) SendFile(ctx context.Context, r *SendFileRequest) (*StatusMessageIDResponse, error)
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)
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)
func (*Bot) SendText ¶
func (b *Bot) SendText(ctx context.Context, r *SendTextRequest) (*StatusMessageIDResponse, error)
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)
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 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 ¶
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 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 ¶
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 ¶
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