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// NewLocation shares your location.
157// Perhaps set a ChatAction of ChatFindLocation 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// NewChatAction 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// NewUserProfilePhotos 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// NewUpdate 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// NewWebhook 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}