TeleAds SDK
This repository holds SDK related to TeleAds.
Requirements
Installation
To install the teleads package, use the following command:
go get https://git.teleads.pro/sdk/bots/go
Usage
Importing the Package
Import the teleads package into your Go code:
import "git.teleads.pro/sdk/bots/go"
Creating a BAP Client
To create a new instance of the BAP client, use the NewBAPClient function:
// Setup BAP
bapClient, err := teleads.NewBAPClient("your-sdk-key")
if err != nil {
log.Fatal(err)
}
defer bapClient.Close()
The SDKKey field is mandatory and represents your TeleAds SDK key.
SDK Key
The SDK Key is generated immediately after connecting your Telegram Bot in TeleAds.
You can find more information on the platform configuration here.
Handling Updates
Use the HandleUpdate method of the BAP client to send update data to the TeleAds API:
needHandle, err := bapClient.HandleUpdate(context.Background(), update)
if err != nil {
log.Print(err)
}
If your advertisement mode is set to manual you can mark ad placement in your code by calling:
err = bapClient.SendAdvertisement(context.Background(), update)
if err != nil {
log.Print(err)
}
Interrupting control flow
At times, SDK may introduce telegram updates within its advertisement flow. To maintain the logical consistency of your bot, it is necessary to ignore such updates.
The bap.HandleUpdate method returns a boolean value indicating whether you should proceed with handling the request or skip it as an internal SDK request.
When the method returns false, it signifies that the current request should not be processed by your bot.
Handling Updates Using Middleware (Example on Telebot)
telebot
Use the BapMiddleware
package main
import (
"log"
"time"
"git.teleads.pro/sdk/bots/go/middleware"
tele "gopkg.in/telebot.v3"
)
func main() {
pref := tele.Settings{
Token: "TELEGRAM_TOKEN",
Poller: &tele.LongPoller{Timeout: 10 * time.Second},
}
b, err := tele.NewBot(pref)
if err != nil {
log.Fatal(err)
}
// Bap middleware
b.Use(middleware.TelebotBapMiddleware("your-sdk-key"))
b.Handle("/hello", func(c tele.Context) error {
return c.Send("Hello Moderator!")
})
b.Start()
}
About
Submitting bugs and feature requests
Bugs and feature request are tracked on GitLab
License
Bot Advertising Platform SDK is licensed under the MIT License - see the LICENSE file for details