diff --git a/api.go b/api.go index b8d37c2..8a570fe 100644 --- a/api.go +++ b/api.go @@ -165,17 +165,17 @@ type APIInlineQuery struct { // APIInlineQueryResultPhoto is an image result for an inline query type APIInlineQueryResultPhoto struct { - Type string `json:"type"` - ResultID string `json:"id"` - PhotoURL string `json:"photo_url"` - ThumbURL string `json:"thumb_url"` - Width int `json:"photo_width,omitempty"` - Height int `json:"photo_height,omitempty"` - Title string `json:"title,omitempty"` - Description string `json:"description,omitempty"` - Caption string `json:"caption,omitempty"` - ParseMode string `json:"parse_mode,omitempty"` - ReplyMarkup *APIInlineKeyboardMarkup `json:"reply_markup,omitempty"` + Type string `json:"type"` + ResultID string `json:"id"` + PhotoURL string `json:"photo_url"` + ThumbURL string `json:"thumb_url"` + Width int `json:"photo_width,omitempty"` + Height int `json:"photo_height,omitempty"` + Title string `json:"title,omitempty"` + Description string `json:"description,omitempty"` + Caption string `json:"caption,omitempty"` + ParseMode string `json:"parse_mode,omitempty"` + ReplyMarkup interface{} `json:"reply_markup,omitempty"` //TODO inputMessageContent } diff --git a/broker.go b/broker.go index 0884cbc..4950bb3 100644 --- a/broker.go +++ b/broker.go @@ -35,31 +35,47 @@ func (b *Broker) Close() { b.Socket.Close() } +type MessageOptions struct { + ReplyID *int64 + ReplyMarkup interface{} +} + // SendTextMessage sends a HTML-styles text message to a chat. // A reply_to message ID can be specified as optional parameter. -func (b *Broker) SendTextMessage(chat *APIChat, text string, original *int64) { +func (b *Broker) SendTextMessage(chat *APIChat, text string, extra *MessageOptions) { + msgdata := &ClientTextMessageData{ + Text: text, + ChatID: chat.ChatID, + } + + if extra != nil { + msgdata.ReplyID = extra.ReplyID + msgdata.ReplyMarkup = extra.ReplyMarkup + } + b.sendCmd(ClientCommand{ - Type: CmdSendTextMessage, - TextMessageData: &ClientTextMessageData{ - Text: text, - ChatID: chat.ChatID, - ReplyID: original, - }, + Type: CmdSendTextMessage, + TextMessageData: msgdata, }) } // SendPhoto sends a photo with an optional caption to a chat. // A reply_to message ID can be specified as optional parameter. -func (b *Broker) SendPhoto(chat *APIChat, data []byte, filename string, caption string, original *int64) { +func (b *Broker) SendPhoto(chat *APIChat, data []byte, filename string, caption string, extra *MessageOptions) { + photodata := &ClientPhotoData{ + ChatID: chat.ChatID, + Filename: filename, + Bytes: base64.StdEncoding.EncodeToString(data), + Caption: caption, + } + + if extra != nil { + photodata.ReplyID = extra.ReplyID + } + b.sendCmd(ClientCommand{ - Type: CmdSendPhoto, - PhotoData: &ClientPhotoData{ - ChatID: chat.ChatID, - Filename: filename, - Bytes: base64.StdEncoding.EncodeToString(data), - Caption: caption, - ReplyID: original, - }, + Type: CmdSendPhoto, + PhotoData: photodata, }) } diff --git a/command.go b/command.go index 46e7d5a..8b80a94 100644 --- a/command.go +++ b/command.go @@ -51,9 +51,10 @@ const ( // ClientTextMessageData is the required data for a CmdSendTextMessage request type ClientTextMessageData struct { - ChatID int64 - Text string - ReplyID *int64 `json:",omitempty"` + ChatID int64 + Text string + ReplyID *int64 `json:",omitempty"` + ReplyMarkup interface{} `json:",omitempty"` } // ClientPhotoData is the required data for a CmdSendPhoto request diff --git a/telegram.go b/telegram.go index b813866..f0c0ee0 100644 --- a/telegram.go +++ b/telegram.go @@ -87,6 +87,13 @@ func (t Telegram) SendTextMessage(data ClientTextMessageData) { if data.ReplyID != nil { postdata["reply_to_message_id"] = []string{strconv.FormatInt(*(data.ReplyID), 10)} } + if data.ReplyMarkup != nil { + replyjson, err := json.Marshal(data.ReplyMarkup) + if !checkerr("SendTextMessage/json.Marshal", err) { + return + } + postdata["reply_markup"] = []string{string(replyjson)} + } _, err := http.PostForm(t.apiURL("sendMessage"), postdata) checkerr("SendTextMessage/http.PostForm", err)