types.go (view raw)
1package tgbotapi
2
3import (
4 "encoding/json"
5)
6
7// APIResponse is a response from the Telegram API with the result stored raw.
8type APIResponse struct {
9 Ok bool `json:"ok"`
10 Result json.RawMessage `json:"result"`
11 ErrorCode int `json:"error_code"`
12 Description string `json:"description"`
13}
14
15// Update is an update response, from GetUpdates.
16type Update struct {
17 UpdateID int `json:"update_id"`
18 Message Message `json:"message"`
19}
20
21// User is a user, contained in Message and returned by GetSelf.
22type User struct {
23 ID int `json:"id"`
24 FirstName string `json:"first_name"`
25 LastName string `json:"last_name"`
26 UserName string `json:"username"`
27}
28
29// String displays a simple text version of a user.
30// It is normally a user's username,
31// but falls back to a first/last name as available.
32func (u *User) String() string {
33 if u.UserName != "" {
34 return u.UserName
35 }
36
37 name := u.FirstName
38 if u.LastName != "" {
39 name += " " + u.LastName
40 }
41
42 return name
43}
44
45// GroupChat is a group chat, and not currently in use.
46type GroupChat struct {
47 ID int `json:"id"`
48 Title string `json:"title"`
49}
50
51// UserOrGroupChat is returned in Message, because it's not clear which it is.
52type UserOrGroupChat struct {
53 ID int `json:"id"`
54 FirstName string `json:"first_name"`
55 LastName string `json:"last_name"`
56 UserName string `json:"username"`
57 Title string `json:"title"`
58}
59
60// Message is returned by almost every request, and contains data about almost anything.
61type Message struct {
62 MessageID int `json:"message_id"`
63 From User `json:"from"`
64 Date int `json:"date"`
65 Chat UserOrGroupChat `json:"chat"`
66 ForwardFrom User `json:"forward_from"`
67 ForwardDate int `json:"forward_date"`
68 ReplyToMessage *Message `json:"reply_to_message"`
69 Text string `json:"text"`
70 Audio Audio `json:"audio"`
71 Document Document `json:"document"`
72 Photo []PhotoSize `json:"photo"`
73 Sticker Sticker `json:"sticker"`
74 Video Video `json:"video"`
75 Contact Contact `json:"contact"`
76 Location Location `json:"location"`
77 NewChatParticipant User `json:"new_chat_participant"`
78 LeftChatParticipant User `json:"left_chat_participant"`
79 NewChatTitle string `json:"new_chat_title"`
80 NewChatPhoto string `json:"new_chat_photo"`
81 DeleteChatPhoto bool `json:"delete_chat_photo"`
82 GroupChatCreated bool `json:"group_chat_created"`
83}
84
85// PhotoSize contains information about photos, including ID and Width and Height.
86type PhotoSize struct {
87 FileID string `json:"file_id"`
88 Width int `json:"width"`
89 Height int `json:"height"`
90 FileSize int `json:"file_size"`
91}
92
93// Audio contains information about audio, including ID and Duration.
94type Audio struct {
95 FileID string `json:"file_id"`
96 Duration int `json:"duration"`
97 MimeType string `json:"mime_type"`
98 FileSize int `json:"file_size"`
99}
100
101// Document contains information about a document, including ID and a Thumbnail.
102type Document struct {
103 FileID string `json:"file_id"`
104 Thumbnail PhotoSize `json:"thumb"`
105 FileName string `json:"file_name"`
106 MimeType string `json:"mime_type"`
107 FileSize int `json:"file_size"`
108}
109
110// Sticker contains information about a sticker, including ID and Thumbnail.
111type Sticker struct {
112 FileID string `json:"file_id"`
113 Width int `json:"width"`
114 Height int `json:"height"`
115 Thumbnail PhotoSize `json:"thumb"`
116 FileSize int `json:"file_size"`
117}
118
119// Video contains information about a video, including ID and duration and Thumbnail.
120type Video struct {
121 FileID string `json:"file_id"`
122 Width int `json:"width"`
123 Height int `json:"height"`
124 Duration int `json:"duration"`
125 Thumbnail PhotoSize `json:"thumb"`
126 MimeType string `json:"mime_type"`
127 FileSize int `json:"file_size"`
128 Caption string `json:"caption"`
129}
130
131// Contact contains information about a contact, such as PhoneNumber and UserId.
132type Contact struct {
133 PhoneNumber string `json:"phone_number"`
134 FirstName string `json:"first_name"`
135 LastName string `json:"last_name"`
136 UserID string `json:"user_id"`
137}
138
139// Location contains information about a place, such as Longitude and Latitude.
140type Location struct {
141 Longitude float32 `json:"longitude"`
142 Latitude float32 `json:"latitude"`
143}
144
145// UserProfilePhotos contains information a set of user profile photos.
146type UserProfilePhotos struct {
147 TotalCount int `json:"total_count"`
148 Photos []PhotoSize `json:"photos"`
149}
150
151// ReplyKeyboardMarkup allows the Bot to set a custom keyboard.
152type ReplyKeyboardMarkup struct {
153 Keyboard [][]string `json:"keyboard"`
154 ResizeKeyboard bool `json:"resize_keyboard"`
155 OneTimeKeyboard bool `json:"one_time_keyboard"`
156 Selective bool `json:"selective"`
157}
158
159// ReplyKeyboardHide allows the Bot to hide a custom keyboard.
160type ReplyKeyboardHide struct {
161 HideKeyboard bool `json:"hide_keyboard"`
162 Selective bool `json:"selective"`
163}
164
165// ForceReply allows the Bot to have users directly reply to it without additional interaction.
166type ForceReply struct {
167 ForceReply bool `json:"force_reply"`
168 Selective bool `json:"selective"`
169}