Giter Club home page Giter Club logo

bap-sdk-php's Introduction

Bot Advertising Platform SDK

This repository holds SDK related to Bot Advertising Platform.

Requirements

  • PHP 5.3 or later
  • ext-sockets

Installation

Install the latest version with

composer require codd-tech/bap-sdk-php

Installing ext-sockets

The socket extension implements a low-level interface to the socket communication.

The BAP SDK uses the UDP protocol for data transfer to ensure minimal SDK overhead for the user.

To install socket extension add the following line to your php.ini:

extension=php_sockets.dll

Or add RUN docker-php-ext-install sockets to your project's Dockerfile if you are using official php image.

Usage

SDK accepts single update from the Telegram bot as an associative array.

Basic usage

$bap = new \CoddTech\Bap\BAP('<api key>');
$bap->handleTelegramUpdates($update);

If your advertisement mode is set to manual you can mark ad placement in your code by calling:

$bap->advertisement($update);

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::handleTelegramUpdates 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.

Usage with PHP Telegram Bot package

If you are using PHP Telegram Bot package you can call SDK inside custom update filter, eg:

$telegram = new Longman\TelegramBot\Telegram($bot_api_key, $bot_username);

$bap = new \CoddTech\Bap\BAP('<api key>');
$telegram->setUpdateFilter(function (Update $update, Telegram $telegram, &$reason = 'Update denied by update_filter') use ($bap) {
    return $bap->handleTelegramUpdates($update->getRawData());
});

For manual advertisement mode(Should be turned on in settings) call following in the desired ad placements.

$bap->advertisement($update);

API Key

API key is not your Telegram bot token.

API key must be obtained from socialjet.pro

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-php's People

Contributors

aggrrrh avatar kkkotov avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

fonclub

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.