Documentation ¶
Overview ¶
Golang (Go) implementation for the Telegram Bot API.
Example ¶
package main import ( "github.com/eternnoir/gotelebot" ) func main() { // Echo Bot example. bot := gotelebot.InitTeleBot("TOKEN") // Create gotelebot instance go bot.StartPolling(true, 0) // Start get new message whit goroutine and default timeout. newMsgChan := bot.Messages for { m := <-newMsgChan // Get new messaage, when new message arrive. if m.Text != "" { // Check message is text message. bot.SendMessage(int(m.Chat.Id), m.Text, nil) } } }
Output:
Index ¶
- type AnswerInlineQueryOptional
- type GetUserProfilePhotosOptional
- type Optional
- type SendAudioOptional
- type SendDocumentOptional
- type SendLocationOptional
- type SendMessageOptional
- type SendPhotoOptional
- type SendStickerOptional
- type SendVideoOptional
- type SendVoiceOptional
- type TeleBot
- func (bot *TeleBot) AnswerInlineQuery(inlineQueryId string, results []interface{}, opt *AnswerInlineQueryOptional) (bool, error)
- func (bot *TeleBot) DownloadFile(fileId string) (*[]byte, error)
- func (bot *TeleBot) ForwardMessage(chatid, from_chat_id, message_id int) (*types.Message, error)
- func (bot *TeleBot) GetFile(fileId string) (*types.File, error)
- func (bot *TeleBot) GetMe() (*types.User, error)
- func (bot *TeleBot) GetUpdates(offset, limit string, timeout int) ([]*types.Update, error)
- func (bot *TeleBot) GetUserProfilePhotos(userid int, opt *GetUserProfilePhotosOptional) (*types.UserProfilePhotos, error)
- func (bot *TeleBot) SendAudio(chatid int, audio string, opt *SendAudioOptional) (*types.Message, error)
- func (bot *TeleBot) SendChatAction(chatid int, action string) (string, error)
- func (bot *TeleBot) SendDocument(chatid int, document string, opt *SendDocumentOptional) (*types.Message, error)
- func (bot *TeleBot) SendLocation(chatid int, latitude, longitude float64, opt *SendLocationOptional) (*types.Message, error)
- func (bot *TeleBot) SendMessage(chatid int, text string, opt *SendMessageOptional) (*types.Message, error)
- func (bot *TeleBot) SendPhoto(chatid int, photo string, opt *SendPhotoOptional) (*types.Message, error)
- func (bot *TeleBot) SendSticker(chatid int, sticker string, opt *SendStickerOptional) (*types.Message, error)
- func (bot *TeleBot) SendVideo(chatid int, video string, opt *SendVideoOptional) (*types.Message, error)
- func (bot *TeleBot) SendVoice(chatid int, voice string, opt *SendVoiceOptional) (*types.Message, error)
- func (bot *TeleBot) StartPolling(nonStop bool, timeout int) error
- func (bot *TeleBot) StopPolling()
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnswerInlineQueryOptional ¶
func (*AnswerInlineQueryOptional) AppendPayload ¶
func (opt *AnswerInlineQueryOptional) AppendPayload(payload *url.Values)
type GetUserProfilePhotosOptional ¶
func (*GetUserProfilePhotosOptional) AppendPayload ¶
func (opt *GetUserProfilePhotosOptional) AppendPayload(payload *url.Values)
type SendAudioOptional ¶
type SendAudioOptional struct { // Duration of the audio in seconds Duration *int Performer *string Title *string ReplyToMessageId *int ReplyMarkup *types.ReplyMarkup }
Optional parameters for SendAudio method
func (*SendAudioOptional) AppendPayload ¶
func (opt *SendAudioOptional) AppendPayload(payload *url.Values)
type SendDocumentOptional ¶
type SendDocumentOptional struct { ReplyToMessageId *int ReplyMarkup *types.ReplyMarkup }
Optional parameters for SendDocument method
func (*SendDocumentOptional) AppendPayload ¶
func (opt *SendDocumentOptional) AppendPayload(payload *url.Values)
type SendLocationOptional ¶
type SendLocationOptional struct { ReplyToMessageId *int ReplyMarkup *types.ReplyMarkup }
Optional parameters for SendLocation method
func (*SendLocationOptional) AppendPayload ¶
func (opt *SendLocationOptional) AppendPayload(payload *url.Values)
type SendMessageOptional ¶
type SendMessageOptional struct { // Send Markdown, if you want Telegram apps to show bold, italic and inline URLs in your bot's message. ParseMode *string // Disables link previews for links in this message DisableWebPagePreview *bool ReplyToMessageId *int ReplyMarkup *types.ReplyMarkup }
Optional parameters for SendMessage method
func (*SendMessageOptional) AppendPayload ¶
func (opt *SendMessageOptional) AppendPayload(payload *url.Values)
type SendPhotoOptional ¶
type SendPhotoOptional struct { // Photo caption Caption *string ReplyToMessageId *int ReplyMarkup *types.ReplyMarkup }
Optional parameters for SendPhoto method
func (*SendPhotoOptional) AppendPayload ¶
func (opt *SendPhotoOptional) AppendPayload(payload *url.Values)
type SendStickerOptional ¶
type SendStickerOptional struct { ReplyToMessageId *int ReplyMarkup *types.ReplyMarkup }
Optional parameters for SendSticker method
func (*SendStickerOptional) AppendPayload ¶
func (opt *SendStickerOptional) AppendPayload(payload *url.Values)
type SendVideoOptional ¶
type SendVideoOptional struct { Duration *int Caption *string ReplyToMessageId *int ReplyMarkup *types.ReplyMarkup }
Optional parameters for SendVideo method
func (*SendVideoOptional) AppendPayload ¶
func (opt *SendVideoOptional) AppendPayload(payload *url.Values)
type SendVoiceOptional ¶
type SendVoiceOptional struct { Duration *int ReplyToMessageId *int ReplyMarkup *types.ReplyMarkup }
Optional parameters for SendVoice method
func (*SendVoiceOptional) AppendPayload ¶
func (opt *SendVoiceOptional) AppendPayload(payload *url.Values)
type TeleBot ¶
type TeleBot struct { Messages chan (*types.Message) InlineQuerys chan (*types.InlineQuery) ChosenInlineResults chan (*types.ChosenInlineResult) Offset float64 // contains filtered or unexported fields }
func InitTeleBot ¶
InitTeleBot is the function to create gotelebot instance.
func (*TeleBot) AnswerInlineQuery ¶
func (bot *TeleBot) AnswerInlineQuery(inlineQueryId string, results []interface{}, opt *AnswerInlineQueryOptional) (bool, error)
func (*TeleBot) DownloadFile ¶
Download file by fileId.
Example ¶
package main import ( "fmt" "io/ioutil" "github.com/eternnoir/gotelebot" ) func main() { token := "TOKEN" bot := gotelebot.InitTeleBot(token) fi := "BQADBQADnAMAAsYifgZph-iT9_z_rgI" file, err := bot.DownloadFile(fi) if err != nil { fmt.Println("Bot get File error") return } ferr := ioutil.WriteFile("/tmp/data", *file, 0644) if ferr != nil { fmt.Println("Write to File error") } }
Output:
func (*TeleBot) ForwardMessage ¶
Use this method to forward messages of any kind. On success, the sent Message type is returned.
func (*TeleBot) GetFile ¶
Use this method to get basic info about a file and prepare it for downloading.
func (*TeleBot) GetMe ¶
Returns basic information about the bot in form of a User object.
Example ¶
package main import ( "fmt" "github.com/eternnoir/gotelebot" ) func main() { bot := gotelebot.InitTeleBot("TOKEN") // Create gotelebot instance me, err := bot.GetMe() // Get user object. if err != nil { fmt.Println(err) return } fmt.Println(me.FirstName) }
Output:
func (*TeleBot) GetUpdates ¶
Use this method to receive incoming updates using long polling. An Array of Update objects is returned.
func (*TeleBot) GetUserProfilePhotos ¶
func (bot *TeleBot) GetUserProfilePhotos(userid int, opt *GetUserProfilePhotosOptional) (*types.UserProfilePhotos, error)
Use this method to get a list of profile pictures for a user.
func (*TeleBot) SendAudio ¶
func (bot *TeleBot) SendAudio(chatid int, audio string, opt *SendAudioOptional) (*types.Message, error)
Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .mp3 format. On success, the sent Message is returned.
Use SendAudioOptional to setup optional parameters. If you don't want use any optional parameters, just asign nil to opt.
func (*TeleBot) SendChatAction ¶
Use this method when you need to tell the user that something is happening on the bot's side.
action can be : "typing" for text messages, "upload_photo" for photos, "record_video" or upload_video for videos, "record_audio" or upload_audio for audio files, "upload_document" for general files, "find_location" for location data.
func (*TeleBot) SendDocument ¶
func (bot *TeleBot) SendDocument(chatid int, document string, opt *SendDocumentOptional) (*types.Message, error)
Use this method to send general files. On success, the sent Message is returned.
Use SendDocumentOptional to setup optional parameters. If you don't want use any optional parameters, just asign nil to opt.
func (*TeleBot) SendLocation ¶
func (bot *TeleBot) SendLocation(chatid int, latitude, longitude float64, opt *SendLocationOptional) (*types.Message, error)
Use this method to send point on the map. On success, the sent Message is returned.
Use SendLocationOptional to setup optional parameters. If you don't want use any optional parameters, just asign nil to opt.
func (*TeleBot) SendMessage ¶
func (bot *TeleBot) SendMessage(chatid int, text string, opt *SendMessageOptional) (*types.Message, error)
Use this method to send text messages. On success, the sent Message type is returned.
Use SendMessageOptional to setup optional parameters. If you don't want use any optional parameters, just asign nil to opt.
Example ¶
package main import ( "fmt" "github.com/eternnoir/gotelebot" ) func main() { bot := gotelebot.InitTeleBot("TOKEN") // Create gotelebot instance testMsg := "Test Msg" chatid := 11111111 _, err := bot.SendMessage(chatid, testMsg, nil) if err != nil { fmt.Println("Bot send message error") } }
Output:
func (*TeleBot) SendPhoto ¶
func (bot *TeleBot) SendPhoto(chatid int, photo string, opt *SendPhotoOptional) (*types.Message, error)
Use this method to send photos. On success, the sent Message is returned.
Use SendPhotoOptional to setup optional parameters. If you don't want use any optional parameters, just asign nil to opt.
Example ¶
package main import ( "fmt" "github.com/eternnoir/gotelebot" ) func main() { bot := gotelebot.InitTeleBot("TOKEN") // Create gotelebot instance chatid := 11111111 filePath := "./test_data/go.png" _, err := bot.SendPhoto(chatid, filePath, nil) if err != nil { fmt.Println("Bot send Photo error") } }
Output:
func (*TeleBot) SendSticker ¶
func (bot *TeleBot) SendSticker(chatid int, sticker string, opt *SendStickerOptional) (*types.Message, error)
Use this method to send .webp stickers. On success, the sent Message is returned.
Use SendStickerOptional to setup optional parameters. If you don't want use any optional parameters, just asign nil to opt.
func (*TeleBot) SendVideo ¶
func (bot *TeleBot) SendVideo(chatid int, video string, opt *SendVideoOptional) (*types.Message, error)
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
Use SendVideoOptional to setup optional parameters. If you don't want use any optional parameters, just asign nil to opt.
func (*TeleBot) SendVoice ¶
func (bot *TeleBot) SendVoice(chatid int, voice string, opt *SendVoiceOptional) (*types.Message, error)
Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned.
Use SendVideoOptional to setup optional parameters. If you don't want use any optional parameters, just asign nil to opt.
func (*TeleBot) StartPolling ¶
Let gotelebot always try to get new messages. This function will put new message to gotelebot's Message channel.
func (*TeleBot) StopPolling ¶
func (bot *TeleBot) StopPolling()
Let gotelebot stop polling new messages.