helpers.go (view raw)
1package tgbotapi
2
3import (
4 "net/url"
5)
6
7// Creates a new Message.
8// Perhaps set a ChatAction of CHAT_TYPING while processing.
9//
10// chatId is where to send it, text is the message text.
11func NewMessage(chatId int, text string) MessageConfig {
12 return MessageConfig{
13 ChatId: chatId,
14 Text: text,
15 DisableWebPagePreview: false,
16 ReplyToMessageId: 0,
17 }
18}
19
20// Creates a new forward.
21//
22// chatId is where to send it, fromChatId is the source chat,
23// and messageId is the Id of the original message.
24func NewForward(chatId int, fromChatId int, messageId int) ForwardConfig {
25 return ForwardConfig{
26 ChatId: chatId,
27 FromChatId: fromChatId,
28 MessageId: messageId,
29 }
30}
31
32// Creates a new photo uploader.
33// This requires a file on the local filesystem to upload to Telegram.
34// Perhaps set a ChatAction of CHAT_UPLOAD_PHOTO while processing.
35//
36// chatId is where to send it, filename is the path to the file.
37func NewPhotoUpload(chatId int, filename string) PhotoConfig {
38 return PhotoConfig{
39 ChatId: chatId,
40 UseExistingPhoto: false,
41 FilePath: filename,
42 }
43}
44
45// Shares an existing photo.
46// You may use this to reshare an existing photo without reuploading it.
47//
48// chatId is where to send it, fileId is the Id of the file already uploaded.
49func NewPhotoShare(chatId int, fileId string) PhotoConfig {
50 return PhotoConfig{
51 ChatId: chatId,
52 UseExistingPhoto: true,
53 FileId: fileId,
54 }
55}
56
57// Creates a new audio uploader.
58// This requires a file on the local filesystem to upload to Telegram.
59// Perhaps set a ChatAction of CHAT_RECORD_AUDIO or CHAT_UPLOAD_AUDIO while processing.
60//
61// chatId is where to send it, filename is the path to the file.
62func NewAudioUpload(chatId int, filename string) AudioConfig {
63 return AudioConfig{
64 ChatId: chatId,
65 UseExistingAudio: false,
66 FilePath: filename,
67 }
68}
69
70// Shares an existing audio file.
71// You may use this to reshare an existing audio file without reuploading it.
72//
73// chatId is where to send it, fileId is the Id of the audio already uploaded.
74func NewAudioShare(chatId int, fileId string) AudioConfig {
75 return AudioConfig{
76 ChatId: chatId,
77 UseExistingAudio: true,
78 FileId: fileId,
79 }
80}
81
82// Creates a new document uploader.
83// This requires a file on the local filesystem to upload to Telegram.
84// Perhaps set a ChatAction of CHAT_UPLOAD_DOCUMENT while processing.
85//
86// chatId is where to send it, filename is the path to the file.
87func NewDocumentUpload(chatId int, filename string) DocumentConfig {
88 return DocumentConfig{
89 ChatId: chatId,
90 UseExistingDocument: false,
91 FilePath: filename,
92 }
93}
94
95// Shares an existing document.
96// You may use this to reshare an existing document without reuploading it.
97//
98// chatId is where to send it, fileId is the Id of the document already uploaded.
99func NewDocumentShare(chatId int, fileId string) DocumentConfig {
100 return DocumentConfig{
101 ChatId: chatId,
102 UseExistingDocument: true,
103 FileId: fileId,
104 }
105}
106
107// Creates a new sticker uploader.
108// This requires a file on the local filesystem to upload to Telegram.
109//
110// chatId is where to send it, filename is the path to the file.
111func NewStickerUpload(chatId int, filename string) StickerConfig {
112 return StickerConfig{
113 ChatId: chatId,
114 UseExistingSticker: false,
115 FilePath: filename,
116 }
117}
118
119// Shares an existing sticker.
120// You may use this to reshare an existing sticker without reuploading it.
121//
122// chatId is where to send it, fileId is the Id of the sticker already uploaded.
123func NewStickerShare(chatId int, fileId string) StickerConfig {
124 return StickerConfig{
125 ChatId: chatId,
126 UseExistingSticker: true,
127 FileId: fileId,
128 }
129}
130
131// Creates a new video uploader.
132// This requires a file on the local filesystem to upload to Telegram.
133// Perhaps set a ChatAction of CHAT_RECORD_VIDEO or CHAT_UPLOAD_VIDEO while processing.
134//
135// chatId is where to send it, filename is the path to the file.
136func NewVideoUpload(chatId int, filename string) VideoConfig {
137 return VideoConfig{
138 ChatId: chatId,
139 UseExistingVideo: false,
140 FilePath: filename,
141 }
142}
143
144// Shares an existing video.
145// You may use this to reshare an existing video without reuploading it.
146//
147// chatId is where to send it, fileId is the Id of the video already uploaded.
148func NewVideoShare(chatId int, fileId string) VideoConfig {
149 return VideoConfig{
150 ChatId: chatId,
151 UseExistingVideo: true,
152 FileId: fileId,
153 }
154}
155
156// Shares your location.
157// Perhaps set a ChatAction of CHAT_FIND_LOCATION while processing.
158//
159// chatId is where to send it, latitude and longitude are coordinates.
160func NewLocation(chatId int, latitude float64, longitude float64) LocationConfig {
161 return LocationConfig{
162 ChatId: chatId,
163 Latitude: latitude,
164 Longitude: longitude,
165 ReplyToMessageId: 0,
166 ReplyMarkup: nil,
167 }
168}
169
170// Sets a chat action.
171// Actions last for 5 seconds, or until your next action.
172//
173// chatId is where to send it, action should be set via CHAT constants.
174func NewChatAction(chatId int, action string) ChatActionConfig {
175 return ChatActionConfig{
176 ChatId: chatId,
177 Action: action,
178 }
179}
180
181// Gets user profile photos.
182//
183// userId is the Id of the user you wish to get profile photos from.
184func NewUserProfilePhotos(userId int) UserProfilePhotosConfig {
185 return UserProfilePhotosConfig{
186 UserId: userId,
187 Offset: 0,
188 Limit: 0,
189 }
190}
191
192// Gets updates since the last Offset.
193//
194// offset is the last Update Id to include.
195// You likely want to set this to the last Update Id plus 1.
196func NewUpdate(offset int) UpdateConfig {
197 return UpdateConfig{
198 Offset: offset,
199 Limit: 0,
200 Timeout: 0,
201 }
202}
203
204// Creates a new webhook.
205//
206// link is the url parsable link you wish to get the updates.
207func NewWebhook(link string) WebhookConfig {
208 u, _ := url.Parse(link)
209
210 return WebhookConfig{
211 Url: u,
212 Clear: false,
213 }
214}