helpers.go (view raw)
1package tgbotapi
2
3import (
4 "net/url"
5)
6
7// NewMessage creates a new Message.
8// Perhaps set a ChatAction of ChatTyping 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// NewForward 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// NewPhotoUpload creates a new photo uploader.
33// This requires a file on the local filesystem to upload to Telegram.
34// Perhaps set a ChatAction of ChatUploadPhoto 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// NewPhotoShare 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// NewAudioUpload creates a new audio uploader.
58// This requires a file on the local filesystem to upload to Telegram.
59// Perhaps set a ChatAction of ChatRecordAudio or ChatUploadAudio 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// NewAudioShare 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// NewDocumentUpload creates a new document uploader.
83// This requires a file on the local filesystem to upload to Telegram.
84// Perhaps set a ChatAction of ChatUploadDocument 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// NewDocumentShare 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// NewStickerUpload 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// NewStickerShare 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// NewVideoUpload creates a new video uploader.
132// This requires a file on the local filesystem to upload to Telegram.
133// Perhaps set a ChatAction of ChatRecordVideo or ChatUploadVideo 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// NewVideoShare 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// NewVoiceUpload creates a new voice uploader.
157// This requires a file on the local filesystem to upload to Telegram.
158// Perhaps set a ChatAction of ChatRecordVideo or ChatUploadVideo while processing.
159//
160// chatID is where to send it, filename is the path to the file.
161func NewVoiceUpload(chatID int, filename string) VoiceConfig {
162 return VoiceConfig{
163 ChatID: chatID,
164 UseExistingVoice: false,
165 FilePath: filename,
166 }
167}
168
169// NewVoiceShare shares an existing voice.
170// You may use this to reshare an existing voice without reuploading it.
171//
172// chatID is where to send it, fileID is the ID of the video already uploaded.
173func NewVoiceShare(chatID int, fileID string) VoiceConfig {
174 return VoiceConfig{
175 ChatID: chatID,
176 UseExistingVoice: true,
177 FileID: fileID,
178 }
179}
180
181// NewLocation shares your location.
182// Perhaps set a ChatAction of ChatFindLocation while processing.
183//
184// chatID is where to send it, latitude and longitude are coordinates.
185func NewLocation(chatID int, latitude float64, longitude float64) LocationConfig {
186 return LocationConfig{
187 ChatID: chatID,
188 Latitude: latitude,
189 Longitude: longitude,
190 ReplyToMessageID: 0,
191 ReplyMarkup: nil,
192 }
193}
194
195// NewChatAction sets a chat action.
196// Actions last for 5 seconds, or until your next action.
197//
198// chatID is where to send it, action should be set via CHAT constants.
199func NewChatAction(chatID int, action string) ChatActionConfig {
200 return ChatActionConfig{
201 ChatID: chatID,
202 Action: action,
203 }
204}
205
206// NewUserProfilePhotos gets user profile photos.
207//
208// userID is the ID of the user you wish to get profile photos from.
209func NewUserProfilePhotos(userID int) UserProfilePhotosConfig {
210 return UserProfilePhotosConfig{
211 UserID: userID,
212 Offset: 0,
213 Limit: 0,
214 }
215}
216
217// NewUpdate gets updates since the last Offset.
218//
219// offset is the last Update ID to include.
220// You likely want to set this to the last Update ID plus 1.
221func NewUpdate(offset int) UpdateConfig {
222 return UpdateConfig{
223 Offset: offset,
224 Limit: 0,
225 Timeout: 0,
226 }
227}
228
229// NewWebhook creates a new webhook.
230//
231// link is the url parsable link you wish to get the updates.
232func NewWebhook(link string) WebhookConfig {
233 u, _ := url.Parse(link)
234
235 return WebhookConfig{
236 URL: u,
237 Clear: false,
238 }
239}