Giter Club home page Giter Club logo

bap-sdk-go's Introduction

Bot Advertising Platform SDK

This repository holds SDK related to Bot Advertising Platform.

Requirements

Installation

To install the bap package, use the following command:

go get github.com/codd-tech/bap-sdk-go

Usage

Importing the Package

Import the bap-sdk-go package into your Go code:

import "github.com/codd-tech/bap-sdk-go"

Creating a BAP Client

To create a new instance of the BAP client, use the NewBAPClient function:

// Setup BAP
bapClient, err := bap.NewBAPClient("your-api-key")
if err != nil {
    log.Fatal(err)
}
defer bapClient.Close()

The APIKey field is mandatory and represents your Advertising Platform API key.

Handling Updates

Use the HandleUpdate method of the BAP client to send update data to the BAP 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, BAP 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 BAP 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"

	"github.com/codd-tech/bap-sdk-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-api-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 GitHub

License

Bot Advertising Platform SDK is licensed under the MIT License - see the LICENSE file for details

bap-sdk-go's People

Contributors

zetoofficial avatar

Stargazers

 avatar

Watchers

 avatar Kostas Georgiou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.