2017-10-05 14:25:25 +00:00
|
|
|
package telegram
|
|
|
|
|
|
|
|
import json "github.com/pquerna/ffjson/ffjson"
|
|
|
|
|
|
|
|
type SendMessageParameters struct {
|
2017-10-06 07:55:54 +00:00
|
|
|
// Unique identifier for the target chat or username of the target channel
|
|
|
|
// (in the format @channelusername)
|
|
|
|
ChatID int64 `json:"chat_id"`
|
2017-10-05 14:25:25 +00:00
|
|
|
|
|
|
|
// Text of the message to be sent
|
2017-10-06 07:55:54 +00:00
|
|
|
Text string `json:"text"`
|
2017-10-05 14:25:25 +00:00
|
|
|
|
2017-10-06 07:55:54 +00:00
|
|
|
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
|
|
|
// fixed-width text or inline URLs in your bot's message.
|
|
|
|
ParseMode string `json:"parse_mode,omitempty"`
|
2017-10-05 14:25:25 +00:00
|
|
|
|
|
|
|
// Disables link previews for links in this message
|
2017-10-06 07:55:54 +00:00
|
|
|
DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
|
2017-10-05 14:25:25 +00:00
|
|
|
|
2017-10-06 07:55:54 +00:00
|
|
|
// Sends the message silently. Users will receive a notification with no
|
|
|
|
// sound.
|
|
|
|
DisableNotification bool `json:"disable_notification,omitempty"`
|
2017-10-05 14:25:25 +00:00
|
|
|
|
2017-10-13 13:21:34 +00:00
|
|
|
// If the message is a reply, ID of the original message
|
2017-10-09 05:57:38 +00:00
|
|
|
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
2017-10-05 14:25:25 +00:00
|
|
|
|
2017-10-06 07:55:54 +00:00
|
|
|
// Additional interface options. A JSON-serialized object for an inline
|
|
|
|
// keyboard, custom reply keyboard, instructions to remove reply keyboard or
|
|
|
|
// to force a reply from the user.
|
|
|
|
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
|
2017-10-05 14:25:25 +00:00
|
|
|
}
|
|
|
|
|
2017-10-17 11:08:09 +00:00
|
|
|
func NewMessage(chatID int64, text string) *SendMessageParameters {
|
|
|
|
return &SendMessageParameters{
|
|
|
|
ChatID: chatID,
|
|
|
|
Text: text,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-05 14:25:25 +00:00
|
|
|
// SendMessage send text messages. On success, the sent Message is returned.
|
|
|
|
func (bot *Bot) SendMessage(params *SendMessageParameters) (*Message, error) {
|
|
|
|
dst, err := json.Marshal(*params)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := bot.request(dst, "sendMessage", nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var data Message
|
|
|
|
err = json.Unmarshal(*resp.Result, &data)
|
|
|
|
return &data, err
|
|
|
|
}
|