Skip to content

Commit

Permalink
Telebot now compiles! :-)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Byrd committed Nov 18, 2017
1 parent dbc2cd7 commit b6938a1
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 114 deletions.
28 changes: 14 additions & 14 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (b *Bot) poll(

func (b *Bot) sendText(to Recipient, text string, opt *SendOptions) (*Message, error) {
params := map[string]string{
"chat_id": to.Destination(),
"chat_id": to.Recipient(),
"text": text,
}
embedSendOptions(params, opt)
Expand Down Expand Up @@ -166,8 +166,8 @@ func (b *Bot) Reply(to *Message, what interface{}, how ...interface{}) (*Message
// This function will panic upon unsupported payloads and options!
func (b *Bot) Forward(to Recipient, what *Message, how ...interface{}) (*Message, error) {
params := map[string]string{
"chat_id": to.Destination(),
"from_chat_id": strconv.Itoa(what.Origin().ID),
"chat_id": to.Recipient(),
"from_chat_id": what.Chat.Recipient(),
"message_id": strconv.Itoa(what.ID),
}

Expand Down Expand Up @@ -197,7 +197,7 @@ func (b *Bot) Forward(to Recipient, what *Message, how ...interface{}) (*Message
// channel, it can delete any message there.
func (b *Bot) Delete(what *Message) error {
params := map[string]string{
"chat_id": what.Chat.Destination(),
"chat_id": what.Chat.Recipient(),
"message_id": strconv.Itoa(what.ID),
}

Expand All @@ -220,7 +220,7 @@ func (b *Bot) Delete(what *Message) error {
// actions, these are aligned as constants of this package.
func (b *Bot) SendChatAction(recipient Recipient, action ChatAction) error {
params := map[string]string{
"chat_id": recipient.Destination(),
"chat_id": recipient.Recipient(),
"action": string(action),
}

Expand Down Expand Up @@ -295,7 +295,7 @@ func (b *Bot) GetFile(fileID string) (*File, error) {
// LeaveChat makes bot leave a group, supergroup or channel.
func (b *Bot) LeaveChat(recipient Recipient) error {
params := map[string]string{
"chat_id": recipient.Destination(),
"chat_id": recipient.Recipient(),
}

respJSON, err := b.sendCommand("leaveChat", params)
Expand All @@ -314,7 +314,7 @@ func (b *Bot) LeaveChat(recipient Recipient) error {
// Returns a Chat object on success.
func (b *Bot) GetChat(recipient Recipient) (*Chat, error) {
params := map[string]string{
"chat_id": recipient.Destination(),
"chat_id": recipient.Recipient(),
}

respJSON, err := b.sendCommand("getChat", params)
Expand Down Expand Up @@ -349,7 +349,7 @@ func (b *Bot) GetChat(recipient Recipient) (*Chat, error) {
// no administrators were appointed, only the creator will be returned.
func (b *Bot) GetChatAdministrators(recipient Recipient) ([]ChatMember, error) {
params := map[string]string{
"chat_id": recipient.Destination(),
"chat_id": recipient.Recipient(),
}

respJSON, err := b.sendCommand("getChatAdministrators", params)
Expand Down Expand Up @@ -380,7 +380,7 @@ func (b *Bot) GetChatAdministrators(recipient Recipient) ([]ChatMember, error) {
// Returns Int on success.
func (b *Bot) GetChatMembersCount(recipient Recipient) (int, error) {
params := map[string]string{
"chat_id": recipient.Destination(),
"chat_id": recipient.Recipient(),
}

respJSON, err := b.sendCommand("getChatMembersCount", params)
Expand Down Expand Up @@ -411,7 +411,7 @@ func (b *Bot) GetChatMembersCount(recipient Recipient) (int, error) {
// Returns a list[photos][sizes].
func (b *Bot) GetUserProfilePhotos(recipient Recipient) ([][]Photo, error) {
params := map[string]string{
"user_id": recipient.Destination(),
"user_id": recipient.Recipient(),
}

respJSON, err := b.sendCommand("getUserProfilePhotos", params)
Expand Down Expand Up @@ -446,8 +446,8 @@ func (b *Bot) GetUserProfilePhotos(recipient Recipient) ([][]Photo, error) {
// Returns a ChatMember object on success.
func (b *Bot) GetChatMember(recipient Recipient, user User) (ChatMember, error) {
params := map[string]string{
"chat_id": recipient.Destination(),
"user_id": user.Destination(),
"chat_id": recipient.Recipient(),
"user_id": user.Recipient(),
}

respJSON, err := b.sendCommand("getChatMember", params)
Expand Down Expand Up @@ -545,7 +545,7 @@ func (b *Bot) EditInlineMessageText(messageID string, message string, sendOption
// On success, returns edited message object
func (b *Bot) EditMessageCaption(recipient Recipient, messageID int, caption string, inlineKeyboard *InlineKeyboardMarkup) (*Message, error) {
params := map[string]string{
"chat_id": recipient.Destination(),
"chat_id": recipient.Recipient(),
"message_id": strconv.Itoa(messageID),
"caption": caption,
}
Expand Down Expand Up @@ -628,7 +628,7 @@ func (b *Bot) EditInlineMessageCaption(messageID string, caption string, inlineK
// On success, returns edited message object
func (b *Bot) EditMessageReplyMarkup(recipient Recipient, messageID int, inlineKeyboard *InlineKeyboardMarkup) (*Message, error) {
params := map[string]string{
"chat_id": recipient.Destination(),
"chat_id": recipient.Recipient(),
"message_id": strconv.Itoa(messageID),
}

Expand Down
8 changes: 4 additions & 4 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import "strconv"

// User object represents a Telegram user, bot
type User struct {
ID int `json:"id"`
FirstName string `json:"first_name"`
ID int `json:"id"`

LastName string `json:"last_name"`
Username string `json:"username"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Username string `json:"username"`
}

// Recipient returns user ID (see Recipient interface).
Expand Down
6 changes: 3 additions & 3 deletions editable.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ type Editable interface {
// a larger struct, which is often the case (you might
// want to store some metadata alongside, or might not.)
type StoredMessage struct {
MessageID string `sql:"message_id" json:"message_id"`
ChatID int64 `sql:"chat_id" json:"chat_id"`
MessageID int `sql:"message_id" json:"message_id"`
ChatID int64 `sql:"chat_id" json:"chat_id"`
}

func (x StoredMessage) MessageSig() (int, int) {
func (x StoredMessage) MessageSig() (int, int64) {
return x.MessageID, x.ChatID
}
99 changes: 41 additions & 58 deletions media.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Photo struct {
Width int `json:"width"`
Height int `json:"height"`

// (Optional)
Caption string `json:"caption,omitempty"`
}

Expand All @@ -17,107 +18,89 @@ type Audio struct {
// Duration of the recording in seconds as defined by sender.
Duration int `json:"duration"`

// Title (optional) as defined by sender or by audio tags.
Title string `json:"title"`

// Performer (optional) is defined by sender or by audio tags.
Performer string `json:"performer"`

// MIME type (optional) of the file as defined by sender.
Mime string `json:"mime_type"`

Caption string `json:"caption,omitempty"`
}

// Voice object represents a voice note.
type Voice struct {
File

// Duration of the recording in seconds as defined by sender.
Duration int `json:"duration"`

// MIME type (optional) of the file as defined by sender.
Mime string `json:"mime_type"`

Caption string `json:"caption,omitempty"`
// (Optional)
Caption string `json:"caption,omitempty"`
Title string `json:"title,omitempty"`
Performer string `json:"performer,omitempty"`
MIME string `json:"mime_type,omitempty"`
}

// Document object represents a general file (as opposed to Photo or Audio).
// Telegram users can send files of any type of up to 1.5 GB in size.
type Document struct {
File

// Document thumbnail as defined by sender.
Preview Photo `json:"thumb"`

// Original filename as defined by sender.
FileName string `json:"file_name"`

// MIME type of the file as defined by sender.
Mime string `json:"mime_type"`

Caption string `json:"caption,omitempty"`
// (Optional)
Thumbnail *Photo `json:"thumb,omitempty"`
Caption string `json:"caption,omitempty"`
MIME string `json:"mime_type"`
}

// Sticker object represents a WebP image, so-called sticker.
type Sticker struct {
File
// Video object represents a video file.
type Video struct {
Audio

Width int `json:"width"`
Height int `json:"height"`

// Sticker thumbnail in .webp or .jpg format.
Thumbnail Photo `json:"thumb"`
Duration int `json:"duration"`

// Associated emoji
Emoji string `json:"emoji"`
// (Optional)
Thumbnail *Photo `json:"thumb,omitempty"`
MIME string `json:"mime_type,omitempty"`
}

// Video object represents an MP4-encoded video.
type Video struct {
Audio

Width int `json:"width"`
Height int `json:"height"`
// Voice object represents a voice note.
type Voice struct {
File

// Text description of the video as defined by sender.
Caption string `json:"caption,omitempty"`
// Duration of the recording in seconds as defined by sender.
Duration int `json:"duration"`

// Video thumbnail.
Thumbnail Photo `json:"thumb"`
// (Optional)
MIME string `json:"mime_type,omitempty"`
}

// This object represents a video message (available in Telegram apps
// VideoNote represents a video message (available in Telegram apps
// as of v.4.0).
type VideoNote struct {
File

// Duration of the recording in seconds as defined by sender.
Duration int `json:"duration"`

// Video note thumbnail.
Thumbnail Photo `json:"thumb"`
// (Optional)
Thumbnail *Photo `json:"thumb,omitempty"`
}

// Contact object represents a contact to Telegram user
type Contact struct {
UserID int `json:"user_id"`
PhoneNumber string `json:"phone_number"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`

// (Optional)
LastName string `json:"last_name"`
UserID int `json:"user_id,omitempty"`
}

// Location object represents geographic position.
type Location struct {
Lat float32 `json:"latitude"`
Lng float32 `json:"longitude"`
// Latitude
Lat float64 `json:"latitude"`
// Longitude
Lng float64 `json:"longitude"`
}

// Venue object represents a venue location with name, address and
// optional foursquare ID.
type Venue struct {
Location Location `json:"location"`
Title string `json:"title"`
Address string `json:"address"`
FoursquareID string `json:"foursquare_id,omitempty"`
Location Location `json:"location"`
Title string `json:"title"`
Address string `json:"address"`

// (Optional)
FoursquareID string `json:"foursquare_id,omitempty"`
}
24 changes: 16 additions & 8 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,27 @@ type Message struct {
// For message sent to channels, Sender will be nil
Sender *User `json:"from"`

// Unixtime, use Message.Time() to get time.Time
Unixtime int64 `json:"date"`

// A group chat message belongs to.
Chat *Chat `json:"chat"`

// (Optional) Time of last edit in Unix
LastEdited int64 `json:"edit_date"`

// For forwarded messages, sender of the original message.
OriginalSender *User `json:"forward_from"`

// For forwarded messages, chat of the original message when forwarded from a channel.
// For forwarded messages, chat of the original message when
// forwarded from a channel.
OriginalChat *Chat `json:"forward_from_chat"`

// For forwarded messages, unixtime of the original message.
OriginalUnixtime int `json:"forward_date"`

// For replies, ReplyTo represents the original message.
//
// Note that the Message object in this field will not
// contain further ReplyTo fields even if it
// itself is a reply.
Expand All @@ -34,12 +40,20 @@ type Message struct {
// For a text message, the actual UTF-8 text of the message.
Text string `json:"text"`

// For text messages, special entities like usernames, URLs, bot commands,
// etc. that appear in the text.
Entities []MessageEntity `json:"entities,omitempty"`

// Author signature (in channels).
Signature string `json:"author_signature"`

// Some messages containing media, may as well have a caption.
Caption string `json:"caption,omitempty"`

// For messages with a caption, special entities like usernames, URLs,
// bot commands, etc. that appear in the caption.
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`

// For an audio recording, information about it.
Audio *Audio `json:"audio"`

Expand Down Expand Up @@ -67,9 +81,6 @@ type Message struct {
// For a location, its longitude and latitude.
Location *Location `json:"location"`

// A group chat message belongs to.
Chat *Chat `json:"chat"`

// For a service message, represents a user,
// that just got added to chat, this message came from.
//
Expand Down Expand Up @@ -146,9 +157,6 @@ type Message struct {
//
// Sender would lead to creator of the migration.
MigrateFrom int64 `json:"migrate_from_chat_id"`

Entities []MessageEntity `json:"entities,omitempty"`
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
}

// MessageEntity object represents "special" parts of text messages,
Expand Down Expand Up @@ -220,7 +228,7 @@ func (m *Message) IsService() bool {
fact = fact || m.ChatPhotoDeleted
fact = fact || m.ChatCreated
fact = fact || m.SuperGroupCreated
fact = fact || (m.MigrateTo != m.MigrateFrom != 0)
fact = fact || (m.MigrateTo != m.MigrateFrom)

return fact
}
4 changes: 4 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ type ReplyMarkup struct {
}

// KeyboardButton represents a button displayed in reply-keyboard.
//
// Set either Contact or Location to true in order to request
// sensitive info, such as user's phone number or current location.
// (Available in private chats only)
type KeyboardButton struct {
Text string `json:"text"`

Expand Down
Loading

0 comments on commit b6938a1

Please sign in to comment.