chat: add voice schedule support

pull/408/head
Nikita 3 years ago
parent 123e689049
commit 0f7e5b74dd

@ -374,6 +374,19 @@ func (b *Bot) ProcessUpdate(upd Update) {
return
}
if m.VoiceChatSchedule != nil {
if handler, ok := b.handlers[OnVoiceChatScheduled]; ok {
handler, ok := handler.(func(*Message))
if !ok {
panic("telebot: voice chat scheduled is bad")
}
b.runHandler(func() { handler(m) })
}
return
}
}
if upd.EditedMessage != nil {

@ -221,6 +221,8 @@ type Message struct {
// Inline keyboard attached to the message.
ReplyMarkup InlineKeyboardMarkup `json:"reply_markup"`
VoiceChatSchedule *VoiceChatSchedule `json:"voice_chat_scheduled,omitempty"`
// For a service message, a voice chat started in the chat.
VoiceChatStarted *VoiceChatStarted `json:"voice_chat_started,omitempty"`

@ -317,6 +317,7 @@ func (i *Invoice) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error)
"payload": i.Payload,
"provider_token": i.Token,
"currency": i.Currency,
"max_tip_amount": strconv.Itoa(i.MaxTipAmount),
"need_name": strconv.FormatBool(i.NeedName),
"need_phone_number": strconv.FormatBool(i.NeedPhoneNumber),
"need_email": strconv.FormatBool(i.NeedEmail),
@ -343,6 +344,9 @@ func (i *Invoice) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error)
data, _ := json.Marshal(i.Prices)
params["prices"] = string(data)
}
if len(i.SuggestedTipAmounts) > 0 {
params["suggested_tip_amounts"] = sliceIntToString(i.SuggestedTipAmounts)
}
b.embedSendOptions(params, opt)
data, err := b.Raw("sendInvoice", params)

@ -154,6 +154,11 @@ const (
//
// Handler: func(*Message)
OnAutoDeleteTimer = "\amessage_auto_delete_timer_changed"
// Will fire on OnVoiceChatScheduled
//
// Handler: func(*Message)
OnVoiceChatScheduled = "\avoice_chat_scheduled"
)
// ChatAction is a client-side status indicating bot activity.

@ -251,3 +251,11 @@ func isUserInList(user *User, list []User) bool {
}
return false
}
func sliceIntToString(ns []int) (s string) {
for _, n := range ns {
s += strconv.Itoa(n) + ","
}
s = s[:len(s)-1]
return
}

@ -1,5 +1,7 @@
package telebot
import "time"
// VoiceChatStarted represents a service message about a voice chat
// started in the chat.
type VoiceChatStarted struct{}
@ -15,3 +17,13 @@ type VoiceChatEnded struct {
type VoiceChatPartecipantsInvited struct {
Users []User `json:"users"`
}
// VoiceChatSchedule represents a service message about a voice chat scheduled in the chat.
type VoiceChatSchedule struct {
StartUnixTime int64 `json:"start_date"`
}
// ExpireDate returns the point when the voice chat is supposed to be started by a chat administrator.
func (v *VoiceChatSchedule) ExpireDate() time.Time {
return time.Unix(v.StartUnixTime, 0)
}

Loading…
Cancel
Save