Skip to content

Commit

Permalink
telebot: refactor bot api 7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
demget committed Aug 9, 2024
1 parent 8d98398 commit b85939e
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 39 deletions.
22 changes: 0 additions & 22 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1271,28 +1271,6 @@ func (b *Bot) botInfo(language, key string) (*BotInfo, error) {
return resp.Result, nil
}

// BusinessConnection use this method to get information about the connection of the bot with a business account.
// Returns a BusinessConnection object on success.
func (b *Bot) BusinessConnection(connectionID string) (*BusinessConnection, error) {
params := map[string]string{
"business_connection_id": connectionID,
}

data, err := b.Raw("getBusinessConnection", params)
if err != nil {
return nil, err
}

var resp struct {
Result *BusinessConnection
}

if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return resp.Result, nil
}

func extractEndpoint(endpoint interface{}) string {
switch end := endpoint.(type) {
case string:
Expand Down
31 changes: 27 additions & 4 deletions busines.go → business.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package telebot

import "time"
import (
"encoding/json"
"time"
)

type BusinessConnection struct {
// Unique identifier of the business connection
ID string `json:"id"`

// Business account user that created the business connection
User *User `json:"user"`
Sender *User `json:"user"`

// Identifier of a private chat with the user who created the business connection. This
// number may have more than 32 significant bits and some programming languages may
Expand All @@ -22,7 +25,7 @@ type BusinessConnection struct {
CanReply bool `json:"can_reply"`

// True, if the connection is active
IsEnabled bool `json:"is_enabled"`
Enabled bool `json:"is_enabled"`
}

// Time returns the moment of business connection creation in local time.
Expand Down Expand Up @@ -76,8 +79,28 @@ type BusinessOpeningHoursInterval struct {

type BusinessOpeningHours struct {
// Unique name of the time zone for which the opening hours are defined
TimeZoneName string `json:"time_zone_name"`
Timezone string `json:"time_zone_name"`

// List of time intervals describing business opening hours
OpeningHours []BusinessOpeningHoursInterval `json:"opening_hours"`
}

// BusinessConnection returns the information about the connection of the bot with a business account.
func (b *Bot) BusinessConnection(id string) (*BusinessConnection, error) {
params := map[string]string{
"business_connection_id": id,
}

data, err := b.Raw("getBusinessConnection", params)
if err != nil {
return nil, err
}

var resp struct {
Result *BusinessConnection
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return resp.Result, nil
}
1 change: 1 addition & 0 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ type Story struct {
// Chat that posted the story
Poster *Chat `json:"chat"`
}

type Birthdate struct {
// Day of the user's birth; 1-31
Day int `json:"day"`
Expand Down
14 changes: 8 additions & 6 deletions markup.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,16 @@ type ReplyRecipient struct {

// RecipientShared combines both UserShared and ChatShared objects.
type RecipientShared struct {
ID int32 `json:"request_id"`
Users []SharedUser `json:"users"`
ChatID int64 `json:"chat_id"`
Title string `json:"title"`
Username string `json:"username"`
Photo []photoSize `json:"photo"`
ID int32 `json:"request_id"` // chat, users
Users []SharedUser `json:"users"` // users only
ChatID int64 `json:"chat_id"` // chat only
Title string `json:"title"` // chat only
Username string `json:"username"` // chat only
Photo *Photo `json:"photo"` // chat only
}

// SharedUser contains information about a user that was shared
// with the bot using a KeyboardButtonRequestUsers button.
type SharedUser struct {
UserID int64 `json:"user_id"`
FirstName string `json:"first_name"`
Expand Down
6 changes: 3 additions & 3 deletions sticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ func (b *Bot) SetCustomEmojiStickerSetThumb(name, id string) error {
return err
}

// ReplaceStickerInSet returns True on success, if existing sticker was replaced with a new one
func (b *Bot) ReplaceStickerInSet(of Recipient, name, oldSticker string, sticker InputSticker) (bool, error) {
// ReplaceStickerInSet returns True on success, if existing sticker was replaced with a new one.
func (b *Bot) ReplaceStickerInSet(of Recipient, stickerSet, oldSticker string, sticker InputSticker) (bool, error) {
files := make(map[string]File)

repr := sticker.File.process("0", files)
Expand All @@ -321,7 +321,7 @@ func (b *Bot) ReplaceStickerInSet(of Recipient, name, oldSticker string, sticker

params := map[string]string{
"user_id": of.Recipient(),
"name": name,
"name": stickerSet,
"old_sticker": oldSticker,
"sticker": string(data),
}
Expand Down
5 changes: 5 additions & 0 deletions telebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ const (

OnBoost = "\aboost_updated"
OnBoostRemoved = "\aboost_removed"

OnBusinessConnection = "\abusiness_connection"
OnBusinessMessage = "\abusiness_message"
OnEditedBusinessMessage = "\aedited_business_message"
OnDeletedBusinessMessages = "\adeleted_business_messages"
)

// ChatAction is a client-side status indicating bot activity.
Expand Down
21 changes: 17 additions & 4 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ func (b *Bot) ProcessUpdate(u Update) {
b.handle(OnPoll, c)
return
}

if u.PollAnswer != nil {
b.handle(OnPollAnswer, c)
return
Expand All @@ -306,12 +305,10 @@ func (b *Bot) ProcessUpdate(u Update) {
b.handle(OnMyChatMember, c)
return
}

if u.ChatMember != nil {
b.handle(OnChatMember, c)
return
}

if u.ChatJoinRequest != nil {
b.handle(OnChatJoinRequest, c)
return
Expand All @@ -321,11 +318,27 @@ func (b *Bot) ProcessUpdate(u Update) {
b.handle(OnBoost, c)
return
}

if u.BoostRemoved != nil {
b.handle(OnBoostRemoved, c)
return
}

if u.BusinessConnection != nil {
b.handle(OnBusinessConnection, c)
return
}
if u.BusinessMessage != nil {
b.handle(OnBusinessMessage, c)
return
}
if u.EditedBusinessMessage != nil {
b.handle(OnEditedBusinessMessage, c)
return
}
if u.DeletedBusinessMessages != nil {
b.handle(OnDeletedBusinessMessages, c)
return
}
}

func (b *Bot) handle(end string, c Context) bool {
Expand Down

0 comments on commit b85939e

Please sign in to comment.