TelegramSDK_php

Bot
in package

Tags
class

Bot

brief

This class is used to communicate with the Telegram Bot API.

details

This class is used to communicate with the Telegram API. It is used to send messages to the Telegram API.

Table of Contents

Constants

DB_LOCATION  = __DIR__ . "/../db"

Properties

$db_stores  : array<string|int, mixed>
$instance  : Bot
$api_url  : string
$bot_token  : string
$callback  : array<string|int, mixed>|null

Methods

__construct()  : mixed
check_for_messages()  : void
get_file()  : string|null
has_access_to_chat()  : bool
send_audio()  : bool
send_custom_request()  : mixed
send_document()  : bool
send_message()  : bool
send_photo()  : bool
send_video()  : bool
send_voice()  : bool
set_callback()  : void
unset_callback()  : array<string|int, mixed>|null
get_updates()  : array<string|int, mixed>
store_message()  : void
call_message_callback()  : void
get_message_type()  : string
is_token_valid()  : bool
process_updates()  : void
save_chat_to_db()  : void
setup_database()  : bool
store_user()  : void

Constants

DB_LOCATION

public mixed DB_LOCATION = __DIR__ . "/../db"

Properties

$db_stores

public static array<string|int, mixed> $db_stores = array()

$callback

protected array<string|int, mixed>|null $callback = null

Methods

__construct()

public __construct(string $bot_token) : mixed
Parameters
$bot_token : string

check_for_messages()

public check_for_messages() : void
Tags
brief

Check for new messages.

get_file()

public get_file(string $file_id) : string|null
Parameters
$file_id : string
Tags
brief

Get file from file id. API docs: https://core.telegram.org/bots/api#getfile

Return values
string|null

has_access_to_chat()

public has_access_to_chat(string $chat_id) : bool
Parameters
$chat_id : string
Tags
brief

Checks whether the bot has access to a chat.

Return values
bool

send_audio()

public send_audio(string $chat_id, string $audio[, array<string|int, mixed> $params = array() ]) : bool
Parameters
$chat_id : string
$audio : string

Audio url or audio id.

$params : array<string|int, mixed> = array()

(Optional) Additional parameters.

Tags
brief

Send an audio to a chat.

Return values
bool

send_custom_request()

public send_custom_request(string $method, array<string|int, mixed> $params) : mixed
Parameters
$method : string
$params : array<string|int, mixed>
Tags
brief

Send custom request to the Telegram API.

send_document()

public send_document(string $chat_id, string $file[, array<string|int, mixed> $params = array() ]) : bool
Parameters
$chat_id : string
$file : string

File url or file id. Sending a file url is not recommended and only works with GIF, PDF, and ZIP files.

$params : array<string|int, mixed> = array()

(Optional) Additional parameters.

Tags
brief

Send a document(file) to a chat.

Return values
bool

send_message()

public send_message(string $chat_id, string $message[, array<string|int, mixed> $params = array() ]) : bool
Parameters
$chat_id : string
$message : string
$params : array<string|int, mixed> = array()

(Optional) Additional parameters.

Tags
brief

Send a message to a chat.

Return values
bool

send_photo()

public send_photo(string $chat_id, string $photo[, array<string|int, mixed> $params = array() ]) : bool
Parameters
$chat_id : string
$photo : string

Photo url or photo id.

$params : array<string|int, mixed> = array()

(Optional) Additional parameters.

Tags
brief

Send a photo to a chat.

Return values
bool

send_video()

public send_video(string $chat_id, string $video[, array<string|int, mixed> $params = array() ]) : bool
Parameters
$chat_id : string
$video : string

Video url or video id.

$params : array<string|int, mixed> = array()

(Optional) Additional parameters.

Tags
brief

Send a video to a chat.

Return values
bool

send_voice()

public send_voice(string $chat_id, string $voice[, array<string|int, mixed> $params = array() ]) : bool
Parameters
$chat_id : string
$voice : string

Voice url or voice id.

$params : array<string|int, mixed> = array()

(Optional) Additional parameters.

Tags
brief

Send a voice to a chat.

Return values
bool

set_callback()

public set_callback(string|array<string|int, mixed> $callable[, string|null $criteria = null ]) : void
Parameters
$callable : string|array<string|int, mixed>
$criteria : string|null = null
Tags
brief

Set the callback function.

throws
InvalidArgumentException

Thrown when the callback is not callable.

unset_callback()

public unset_callback([string|null $criteria = null ]) : array<string|int, mixed>|null
Parameters
$criteria : string|null = null
Tags
brief

Unset the callback function.

Return values
array<string|int, mixed>|null

get_updates()

protected get_updates([int $offset = null ][, int $limit = 100 ][, int $timeout = 0 ][, array<string|int, mixed> $allowed_updates = array("message") ]) : array<string|int, mixed>
Parameters
$offset : int = null

Defaults to only new updates

$limit : int = 100
$timeout : int = 0
$allowed_updates : array<string|int, mixed> = array("message")

Check https://core.telegram.org/bots/api#update for more information.

Tags
brief

Get updates from the Telegram API. Defaults to only getting new messages.

Return values
array<string|int, mixed>

store_message()

protected store_message( $message) : void
Parameters
$message :
Tags
brief

Save message to database.

call_message_callback()

private call_message_callback(stdClass $message) : void
Parameters
$message : stdClass
Tags
brief

Call callback on new message.

get_message_type()

private get_message_type( $message) : string
Parameters
$message :
Tags
brief

Get message type.

Return values
string

is_token_valid()

private is_token_valid() : bool
Tags
brief

Validate Telegram bot token by testing it.

Return values
bool

process_updates()

private process_updates(array<string|int, mixed> $updates) : void
Parameters
$updates : array<string|int, mixed>
Tags
brief

Process updates.

save_chat_to_db()

private save_chat_to_db(stdClass $message) : void
Parameters
$message : stdClass
Tags
brief

Send chat info from message, to Chat class, for insertion into database.

setup_database()

private setup_database() : bool
Tags
brief

Setup databases using SleekDB.

Return values
bool

store_user()

private store_user(mixed $from) : void
Parameters
$from : mixed
Tags
brief

Save user to database.


        
On this page

Search results