Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ func (b *Bot) CopyMany(to Recipient, msgs []Editable, opts ...*SendOptions) ([]M
// b.Edit(m, tele.Location{42.1337, 69.4242})
// b.Edit(c, "edit inline message from the callback")
// b.Edit(r, "edit message from chosen inline result")
//
// b.Edit(b, &tele.Checklist{...}, &tele.SendOptions{BusinessConnectionID: c.Update().BusinessMessage.BusinessConnectionID})
func (b *Bot) Edit(msg Editable, what interface{}, opts ...interface{}) (*Message, error) {
var (
method string
Expand All @@ -530,6 +532,8 @@ func (b *Bot) Edit(msg Editable, what interface{}, opts ...interface{}) (*Messag
switch v := what.(type) {
case *ReplyMarkup:
return b.EditReplyMarkup(msg, v)
case *Checklist:
return b.EditCheckList(msg, v, opts...)
case Inputtable:
return b.EditMedia(msg, v, opts...)
case string:
Expand Down Expand Up @@ -610,6 +614,28 @@ func (b *Bot) EditReplyMarkup(msg Editable, markup *ReplyMarkup) (*Message, erro
return extractMessage(data)
}

// EditCheckList edits checklist of already sent message.
func (b *Bot) EditCheckList(msg Editable, checklist *Checklist, opt ...interface{}) (*Message, error) {
msgID, chatID := msg.MessageSig()
params := map[string]string{
"chat_id": strconv.FormatInt(chatID, 10),
"message_id": msgID,
}

opts, _ := json.Marshal(checklist)
params["checklist"] = string(opts)

sendOpts := b.extractOptions(opt)
b.embedSendOptions(params, sendOpts)

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

return extractMessage(data)
}

// EditCaption edits already sent photo caption with known recipient and message id.
// This function will panic upon nil Editable.
//
Expand Down
33 changes: 33 additions & 0 deletions checklist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package telebot

// Checklist contains information about a checklist.
// Can be sent only in business chats.
type Checklist struct {
Title string `json:"title"`
Entities []MessageEntity `json:"title_entities,omitempty"`
Tasks []ChecklistTask `json:"tasks"`
OtherCanAddTasks bool `json:"other_can_add_tasks,omitempty"`
OtherCanMarkTasksAsDone bool `json:"other_can_mark_tasks_as_done,omitempty"`
}

// ChecklistTask describes a task in a checklist
type ChecklistTask struct {
ID int64 `json:"id"`
Text string `json:"text"`
Entities []MessageEntity `json:"title_entities,omitempty"`
CompletedByUser *User `json:"completed_by_user,omitempty"`
CompletionUnixDate int64 `json:"completion_date,omitempty"`
}

// ChecklistTasksDone describes a service message about checklist tasks marked as done or not done.
type ChecklistTasksDone struct {
ChecklistMessage *Message `json:"checklist_message,omitempty"`
DoneTasks []int64 `json:"marked_as_done_task_ids,omitempty"`
NotDoneTasks []int64 `json:"marked_as_not_done_task_ids,omitempty"`
}

// ChecklistTasksAdded describes a service message about tasks added to a checklist.
type ChecklistTasksAdded struct {
Message *Message `json:"checklist_message,omitempty"`
Tasks []ChecklistTask `json:"tasks"`
}
9 changes: 9 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@ type Message struct {

// Service message: the user allowed the bot added to the attachment menu to write messages
WriteAccessAllowed *WriteAccessAllowed `json:"write_access_allowed,omitempty"`

// (Optional) Message is a checklist
Checklist *Checklist `json:"checklist,omitempty"`

// (Optional) Service message: some tasks in a checklist were marked as done or not done
ChecklistTasksDone ChecklistTasksDone `json:"checklist_tasks_done,omitempty"`

// (Optional) Service message: tasks were added to a checklist
ChecklistTasksAdded ChecklistTasksAdded `json:"checklist_tasks_added,omitempty"`
}

// MessageEntity object represents "special" parts of text messages,
Expand Down
19 changes: 19 additions & 0 deletions sendable.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,25 @@ func (g *Game) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
return extractMessage(data)
}

// Send delivers checklist through bot b to recipient.
// Works only with a business connection.
func (c *Checklist) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
params := map[string]string{
"chat_id": to.Recipient(),
}
b.embedSendOptions(params, opt)

opts, _ := json.Marshal(c)
params["checklist"] = string(opts)

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

return extractMessage(data)
}

func thumbnailToFilemap(thumb *Photo) map[string]File {
if thumb != nil {
return map[string]File{"thumbnail": thumb.File}
Expand Down