all repos — telegram-bot-api @ cea0df2dae12eccb41669acd95203f3a691da2b0

Golang bindings for the Telegram Bot API

helpers.go (view raw)

  1package tgbotapi
  2
  3import (
  4	"net/url"
  5)
  6
  7func NewMessage(chatId int, text string) MessageConfig {
  8	return MessageConfig{
  9		ChatId: chatId,
 10		Text:   text,
 11		DisableWebPagePreview: false,
 12		ReplyToMessageId:      0,
 13	}
 14}
 15
 16func NewForward(chatId int, fromChatId int, messageId int) ForwardConfig {
 17	return ForwardConfig{
 18		ChatId:     chatId,
 19		FromChatId: fromChatId,
 20		MessageId:  messageId,
 21	}
 22}
 23
 24func NewPhotoUpload(chatId int, filename string) PhotoConfig {
 25	return PhotoConfig{
 26		ChatId:           chatId,
 27		UseExistingPhoto: false,
 28		FilePath:         filename,
 29	}
 30}
 31
 32func NewPhotoShare(chatId int, fileId string) PhotoConfig {
 33	return PhotoConfig{
 34		ChatId:           chatId,
 35		UseExistingPhoto: true,
 36		FileId:           fileId,
 37	}
 38}
 39
 40func NewAudioUpload(chatId int, filename string) AudioConfig {
 41	return AudioConfig{
 42		ChatId:           chatId,
 43		UseExistingAudio: false,
 44		FilePath:         filename,
 45	}
 46}
 47
 48func NewAudioShare(chatId int, fileId string) AudioConfig {
 49	return AudioConfig{
 50		ChatId:           chatId,
 51		UseExistingAudio: true,
 52		FileId:           fileId,
 53	}
 54}
 55
 56func NewDocumentUpload(chatId int, filename string) DocumentConfig {
 57	return DocumentConfig{
 58		ChatId:              chatId,
 59		UseExistingDocument: false,
 60		FilePath:            filename,
 61	}
 62}
 63
 64func NewDocumentShare(chatId int, fileId string) DocumentConfig {
 65	return DocumentConfig{
 66		ChatId:              chatId,
 67		UseExistingDocument: true,
 68		FileId:              fileId,
 69	}
 70}
 71
 72func NewStickerUpload(chatId int, filename string) StickerConfig {
 73	return StickerConfig{
 74		ChatId:             chatId,
 75		UseExistingSticker: false,
 76		FilePath:           filename,
 77	}
 78}
 79
 80func NewStickerShare(chatId int, fileId string) StickerConfig {
 81	return StickerConfig{
 82		ChatId:             chatId,
 83		UseExistingSticker: true,
 84		FileId:             fileId,
 85	}
 86}
 87
 88func NewVideoUpload(chatId int, filename string) VideoConfig {
 89	return VideoConfig{
 90		ChatId:           chatId,
 91		UseExistingVideo: false,
 92		FilePath:         filename,
 93	}
 94}
 95
 96func NewVideoShare(chatId int, fileId string) VideoConfig {
 97	return VideoConfig{
 98		ChatId:           chatId,
 99		UseExistingVideo: true,
100		FileId:           fileId,
101	}
102}
103
104func NewLocation(chatId int, latitude float64, longitude float64) LocationConfig {
105	return LocationConfig{
106		ChatId:           chatId,
107		Latitude:         latitude,
108		Longitude:        longitude,
109		ReplyToMessageId: 0,
110		ReplyMarkup:      nil,
111	}
112}
113
114func NewChatAction(chatId int, action string) ChatActionConfig {
115	return ChatActionConfig{
116		ChatId: chatId,
117		Action: action,
118	}
119}
120
121func NewUserProfilePhotos(userId int) UserProfilePhotosConfig {
122	return UserProfilePhotosConfig{
123		UserId: userId,
124		Offset: 0,
125		Limit:  0,
126	}
127}
128
129func NewUpdate(offset int) UpdateConfig {
130	return UpdateConfig{
131		Offset:  offset,
132		Limit:   0,
133		Timeout: 0,
134	}
135}
136
137func NewWebhook(link string) WebhookConfig {
138	u, _ := url.Parse(link)
139
140	return WebhookConfig{
141		Url:   u,
142		Clear: false,
143	}
144}