laniakea/methods.go

82 lines
2.5 KiB
Go
Raw Normal View History

2024-12-16 00:52:43 +03:00
package laniakea
import "fmt"
var NO_PARAMS = make(map[string]interface{})
2024-12-17 09:23:53 +03:00
func (b *Bot) Updates() ([]*Update, error) {
2024-12-16 00:52:43 +03:00
params := make(map[string]interface{})
params["offset"] = b.updateOffset
params["timeout"] = 30
2024-12-17 09:23:53 +03:00
params["allowed_updates"] = b.updateTypes
2024-12-16 00:52:43 +03:00
data, err := b.request("getUpdates", params)
if err != nil {
return nil, err
}
res := make([]*Update, 0)
for _, u := range data["data"].([]interface{}) {
updateObj := new(Update)
err = MapToStruct(u.(map[string]interface{}), updateObj)
if err != nil {
return res, err
}
b.updateOffset = updateObj.UpdateID + 1
err = b.updateQueue.Enqueue(updateObj)
if err != nil {
return res, err
}
res = append(res, updateObj)
if b.debug {
j, err := MapToJson(u.(map[string]interface{}))
if err != nil {
b.logger.Error(err)
}
b.logger.Debug(fmt.Sprintf("New update: %s\n", j))
}
}
return res, err
}
2024-12-17 09:23:53 +03:00
func (b *Bot) GetMe() (*User, error) {
data, err := b.request("getMe", NO_PARAMS)
if err != nil {
return nil, err
}
user := new(User)
err = MapToStruct(data, user)
return user, err
}
2024-12-16 00:52:43 +03:00
type SendMessageP struct {
2024-12-17 09:23:53 +03:00
BusinessConnectionID string `json:"business_connection_id,omitempty"`
ChatID int `json:"chat_id"`
MessageThreadID int `json:"message_thread_id,omitempty"`
Text string `json:"text"`
2024-12-17 15:31:37 +03:00
ParseMode ParseMode `json:"parse_mode,omitempty"`
2024-12-17 09:23:53 +03:00
Entities []*MessageEntity `json:"entities,omitempty"`
LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"`
DisableNotifications bool `json:"disable_notifications,omitempty"`
ProtectContent bool `json:"protect_content,omitempty"`
AllowPaidBroadcast bool `json:"allow_paid_broadcast,omitempty"`
MessageEffectID string `json:"message_effect_id,omitempty"`
ReplyParameters *ReplyParameters `json:"reply_parameters,omitempty"`
InlineKeyboardMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
// ReplyKeyboardMarkup *ReplyKeyboardMarkup `json:"reply_markup,omitempty"`
2024-12-16 00:52:43 +03:00
}
func (b *Bot) SendMessage(params *SendMessageP) (*Message, error) {
dataP, err := StructToMap(params)
if err != nil {
return nil, err
}
data, err := b.request("sendMessage", dataP)
if err != nil {
return nil, err
}
message := new(Message)
err = MapToStruct(data, message)
return message, err
}