Skip to main content
Version: 4.x

Installation

Composer

You can install the package as usual via Composer:

composer require nutgram/nutgram
tip

If you are using Laravel or Symfony frameworks, be sure to read their dedicated pages for a better development experience.

Configuration

The framework can work out-of-the-box without much configuration, the only mandatory parameter is (obviously) the Telegram API token:

use SergiX44\Nutgram\Nutgram;

$bot = new Nutgram('you telegram token here');

In addition, it's possible to specify a list of options as second argument, like that:

use SergiX44\Nutgram\Nutgram;
use SergiX44\Nutgram\Configuration;

$config = new Configuration(
clientTimeout: 10, // default in seconds, when contacting the Telegram API
);

$bot = new Nutgram('you telegram token here', $config);

Here a list of all the options you can specify:

apiUrl

  • type: string
  • default: 'https://api.telegram.org'
  • Useful if you need to change to a local or different API server.
  • WARNING: If the server does not support HTTP/2, remember to disable enableHttp2 in the configuration.

enableHttp2

  • type: boolean
  • default: true
  • Enable HTTP/2 support

botName

  • type: string
  • default: null
  • Useful when the bot is a group bot (with Group Privacy disabled) and you need to specify the bot name.

isLocal

  • type: boolean
  • default: false
  • Enable the local mode when used along a self-hosted Telegram Bot API server.
    Nutgram will copy the file from your Telegram Bot API server instead downloading it.
  • WARNING: If your local server does not support HTTP/2, remember to disable enableHttp2 in the configuration.

localPathTransformer

  • type: callable(string $path): string
  • default: null
  • Useful if you need to remap a relative file path when used along is_local config.

testEnv

  • type: boolean
  • default: false
  • Enable test environments useful when working with Web Apps.

clientTimeout

  • type: integer
  • default: 5
  • In seconds, define the timeout when sending requests to the Telegram API.

cache

  • type: string or instance
  • default: SergiX44\Nutgram\Cache\Adapters\ArrayCache
  • The object used to store conversation and data, must implements the PSR-16 CacheInterface.

clientOptions

  • type: array
  • default: []
  • An array of options for the underlying Guzzle HTTP client. Checkout the Guzzle documentation for further informations.

pollingTimeout

  • type: integer
  • default: 10
  • In seconds, define the timeout when polling updates from the Telegram API.

pollingLimit

  • type: integer
  • default: 100
  • Define the maximum number of updates to be retrieved from the Telegram API.

pollingAllowedUpdates

  • type: array
  • default: ['message', 'edited_message', 'channel_post', 'edited_channel_post', 'inline_query', 'chosen_inline_result', 'callback_query', 'shipping_query', 'pre_checkout_query', 'poll', 'poll_answer', 'my_chat_member', 'chat_member', 'chat_join_request'];
  • Define the allowed updates to be retrieved from the Telegram API.

logger

container

  • type: Psr\Container\ContainerInterface
  • default: null
  • Delegate container to resolve dependencies.