Download the PHP package natilosir/telegram-bot-sdk without Composer

On this page you can find all versions of the php package natilosir/telegram-bot-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package telegram-bot-sdk

Bot-SDK

A professional SDK for building Telegram Bots, designed with a Laravel-like structure for PHP.

Requirements

Installation

You can install this SDK package via Composer:

ORM

For detailed documentation on the ORM, visit: ORM Documentation

Log::Class

The Log class, along with global lg() and dd() functions in the natilosir\bot namespace, provides a robust logging system for PHP applications, particularly suited for debugging and monitoring in bot frameworks like Telegram bots.

Features

AdvancedLogger Class

Log Class

Global Functions

Usage

The AdvancedLogger is initialized automatically with a default log file (log.html) and sets up error and exception handlers. The Log class and global lg() and dd() functions provide easy ways to log messages or debug data.

Example

Editor.php

Overview

Editor.php is an online code editor that allows users to edit files in a manner similar to Visual Studio Code (VSCode). It provides a user-friendly interface for managing and editing code files directly from your web browser.

Opening Files

By default, the editor opens the file route.php. To open other files, append the file path to the URL, like this:

Handling Unsaved Files

If you encounter an "Error opening file" message when trying to open a file that has not been saved previously, press Ctrl + S. This action will create a new file and automatically save it.

Saving Files

To save changes, click the purple "Save" button in the top right corner of the editor (for mobile users) or use the keyboard shortcut Ctrl + S.

Features

Route::Class

The Route class is used to define routes for handling user inputs in the bot.

Example

To use this class, ensure you include use natilosir\bot\Route; before calling the Route class.

add Method Overview

This method accepts two parameters: patterns and action.

  1. Patterns (Input 1):

    • Specify patterns as either an array or a string to define the command or phrase that triggers the route.
    • Example: If the user sends /start, specify this command in the patterns parameter.
  2. Action (Input 2):
    • The path to the file in the controller directory.
    • Example: For app/Controllers/StartController.php, specify start. The system will automatically locate app/Controllers/StartController.php.
    • To access files in other directories, use . notation, e.g., StartController::class.

Usage

Key Methods

  1. Route::add($uri, $action)

    • Description: Registers one or more input patterns to an action (controller method or callable).
    • Parameters:
    • $uri: A string or array of strings representing the input pattern(s) (e.g., /start, ['/start', 'begin']).
    • $action: The action to execute, either:
      • An array [Controller::class, 'method'] to call a specific controller method.
      • A string representing a controller class name (defaults to __invoke method).
      • A callable function.
    • Returns: A Route instance for method chaining.
    • Example:
  2. Route::state($stateName)

    • Description: Associates a state with the most recently added route, enabling state persistence.
    • Parameters:
    • $stateName: A string representing the state identifier to persist.
    • Returns: A Route instance for method chaining.
    • Example:
  3. Route::def($default)
    • Description: Sets a default action to handle inputs that do not match any defined routes.
    • Parameters:
    • $default: The default action, either an array [Controller::class, 'method'], a string (controller class name), or a callable.
    • Returns: A Route instance for method chaining.
    • Example:

Example Controller

State::Class

The State class allows associating a state with a route, useful for maintaining context in conversational applications (e.g., chatbots). When a route with a state is triggered, the state is set using State::set($stateName) and persists until cleared or overridden.

States are cleared automatically unless the route explicitly sets a state (controlled by the $configclear flag).

Example

In this example:

Request::Class

The Request class is a versatile utility for parsing and handling incoming webhook updates, particularly for Telegram bots, within the natilosir\bot namespace.

Features

Usage

The Request class is instantiated automatically to parse incoming webhook data from php://input. It processes the JSON payload and populates public properties based on the update type.

Example

Public Properties

Common Properties

Message-Specific Properties

Callback Query-Specific Properties

Inline Query-Specific Properties

Shipping Query-Specific Properties

Pre-Checkout Query-Specific Properties

Poll-Specific Properties

Chat Member Update Properties

Key Methods

  1. getInput(): string

    • Description: Returns the primary input for the update (e.g., callbackData for callback_query, query for inline_query, or text).
    • Example:
  2. getUpdateType(): string

    • Description: Returns the type of the update (e.g., message, callback_query).
    • Example:
  3. isCommand(): bool

    • Description: Checks if the message contains a bot command.
    • Example:
  4. getCommand(): string

    • Description: Retrieves the bot command from the message (e.g., /start).
    • Example:
  5. toArray(): array

    • Description: Converts non-empty properties to an array, excluding internal data and updateTypes properties.
    • Example:
  6. toJson(): string

    • Description: Converts non-empty properties to a JSON string.
    • Example:
  7. getRawData(): array

    • Description: Returns the raw JSON data decoded from php://input.
    • Example:
  8. dd(): string and lg(): string
    • Description: Debugging methods that call external dd or lg functions with the request’s array representation.
    • Note: Requires dd and lg functions to be defined.

Http::Class

The Http and HttpResponse classes in the natilosir\bot namespace provide a simple and flexible way to make HTTP requests and handle responses, particularly for interacting with APIs like the Telegram Bot API.

Features

Http Class

Usage

Example

Key Methods

  1. static post($url, array $data = []): HttpResponse

    • Description: Sends a POST request with form data.
    • Example:
  2. static get($url, array $query = []): HttpResponse

    • Description: Sends a GET request with optional query parameters.
    • Example:
  3. static put($url, array $data = []): HttpResponse

    • Description: Sends a PUT request with form data.
    • Example:
  4. static patch($url, array $data = []): HttpResponse

    • Description: Sends a PATCH request with form data.
    • Example:
  5. static delete($url, array $data = []): HttpResponse

    • Description: Sends a DELETE request with optional form data.
    • Example:
  6. withHeaders(array $headers): Http

    • Description: Merges additional headers with existing ones.
    • Example:
  7. withOptions(array $options): Http

    • Description: Merges additional cURL options with existing ones.
    • Example:
  8. send(string $method, string $url, array $options = []): HttpResponse
    • Description: Sends an HTTP request with the specified method, URL, and options.
    • Example:

HttpResponse Class Methods

  1. status(): int

    • Description: Returns the HTTP status code.
    • Example:
  2. body(): stdClass

    • Description: Returns the response body as a stdClass object.
    • Example:
  3. json(): stdClass

    • Description: Alias for body(), returns the response body as a stdClass object.
    • Example:
  4. successful(): bool

    • Description: Checks if the request was successful (status code 200–299).
    • Example:
  5. failed(): bool

    • Description: Checks if the request failed (status code outside 200–299).
    • Example:
  6. dd(): string
    • Description: Debugging method that calls an external dd function with the response data.
    • Note: Requires a dd function to be defined.

Bot::Class

deleteMessage Method

The deleteMessage method allows you to delete a message from a chat.

Parameters

Example

forwardMessage Method

The forwardMessage method forwards a message from one chat to another.

Parameters

Example

sendMessage Method

The sendMessage method sends a text message to a specified chat.

Parameters

Example

copyMessage Method

The copyMessage method copies a message from one chat to another.

Parameters

Example

inline Method

The inline method creates inline keyboard buttons for the bot.

Parameters

Example

keyboard Method

The keyboard method creates a custom keyboard layout for bot messages.

Parameters

Example

editMessageReplyMarkup Method

The editMessageReplyMarkup method edits the reply markup of a message sent by the bot.

Parameters

Example

answerCallbackQuery Method

This method sends a response to a callback query received from a button press.

Parameters

Example

alert Method

The alert method sends an alert to the user in response to a callback query.

Parameters

Example

sendChatAction Method

The sendChatAction method sends a chat action (e.g., typing, uploading) to a specific chat.

Parameters

Example


All versions of telegram-bot-sdk with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
natilosir/jalali Version ^1.0
natilosir/bot Version ^1.0
natilosir/orm Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package natilosir/telegram-bot-sdk contains the following files

Loading the files please wait ....