Skip to content

Commit 27b471a

Browse files
committed
Froze 3.x
1 parent 5537c48 commit 27b471a

23 files changed

+4076
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
5+
# Cache
6+
7+
Nutgram accepts as a cache system any adapter that implements the PSR-16 `CacheInterface` interface.
8+
9+
By default, it uses the internal `ArrayCache` class, which is non-persistent, useful only when the bot is running in
10+
polling mode.
11+
12+
:::danger
13+
Without configuring a cache adapter accordingly, feature like global or per-user object storage and conversations will not work when using the `Webhook` mode.
14+
:::
15+
16+
## Configuration
17+
18+
:::tip
19+
If you are using Laravel or Symfony frameworks, you can skip this section, but take a look at the corresponding section
20+
for your framework:
21+
22+
- [Laravel](laravel.md#cache)
23+
- [Symfony](symfony.md#cache)
24+
:::
25+
26+
To specify a different cache adapter, you need to pass the instance at the bot instantiation. The following example, we
27+
are using the [Symfony Cache](https://symfony.com/doc/current/components/cache.html), since they are providing multiple
28+
adapters out-of-the-box:
29+
30+
```php
31+
use SergiX44\Nutgram\Nutgram;
32+
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
33+
use Symfony\Component\Cache\Psr16Cache;
34+
35+
$psr6Cache = new FilesystemAdapter();
36+
$psr16Cache = new Psr16Cache($psr6Cache);
37+
38+
$bot = new Nutgram('TOKEN', [
39+
'cache' => $psr16Cache
40+
]);
41+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
sidebar_position: 4
3+
---
4+
5+
# Installation
6+
7+
## Composer
8+
9+
You can install the package as usual via Composer:
10+
11+
```bash
12+
composer require nutgram/nutgram
13+
```
14+
15+
:::tip
16+
If you are using Laravel or Symfony frameworks, be sure to read their dedicated pages for a better
17+
development experience.
18+
19+
- [Laravel](laravel.md)
20+
- [Symfony](symfony.md)
21+
:::
22+
23+
## Configuration
24+
25+
The framework can work out-of-the-box without much configuration, the only mandatory parameter is (obviously) the
26+
Telegram API token:
27+
28+
```php
29+
use SergiX44\Nutgram\Nutgram;
30+
31+
$bot = new Nutgram('you telegram token here');
32+
```
33+
34+
In addition, it's possible to specify a list of options as second argument, like that:
35+
36+
```php
37+
use SergiX44\Nutgram\Nutgram;
38+
39+
$config = [
40+
'timeout' => 10, // default in seconds, when contacting the Telegram API
41+
];
42+
43+
$bot = new Nutgram('you telegram token here', $config);
44+
```
45+
46+
Here a list of all the options you can specify:
47+
48+
### `api_url`
49+
50+
- **type:** string
51+
- **default:** `'https://api.telegram.org'`
52+
- Useful if you need to change to a local API server.
53+
54+
### `bot_name`
55+
56+
- **type:** string
57+
- **default:** `null`
58+
- Useful when the bot is a group bot (with [Group Privacy](https://core.telegram.org/bots/features#privacy-mode) *
59+
*disabled**) and you need to specify the bot name.
60+
61+
### `is_local`
62+
63+
- **type:** boolean
64+
- **default:** `false`
65+
- Enable the local mode when used along a self-hosted Telegram Bot API server.<br/>
66+
_Nutgram will copy the file from your Telegram Bot API server instead downloading it._
67+
68+
### `local_path_transformer`
69+
70+
- **type:** callable(string $path): string
71+
- **default:** `null`
72+
- Useful if you need to remap a relative file path when used along `is_local` config.
73+
74+
### `test_env`
75+
76+
- **type:** boolean
77+
- **default:** `null`
78+
- Enable test environments useful when working with [Web Apps](https://core.telegram.org/bots/webapps#testing-web-apps).
79+
80+
### `timeout`
81+
82+
- **type:** integer
83+
- **default:** `10`
84+
- In seconds, define the timeout when sending requests to the Telegram API.
85+
86+
### `cache`
87+
88+
- **type:** string or instance
89+
- **default:** `ArrayCache`
90+
- The object used to store conversation and data, must implements the PSR-16 `CacheInterface`.
91+
92+
### `client`
93+
94+
- **type:** array
95+
- **default:** `[]`
96+
- An array of options for the underlying [Guzzle HTTP client](https://docs.guzzlephp.org/en/stable/quickstart.html).
97+
Checkout the Guzzle documentation for further informations.
98+
99+
### `polling`
100+
101+
- **type:** array
102+
- **default:** `['timeout' => 10, 'limit' => 100]`
103+
- Contains all the options that used when requesting updates to Telegram via the `getUpdates`, it's possible to specify
104+
also the field `allowed_updates` if you want.
105+
106+
### `split_long_messages`
107+
108+
- **type:** boolean
109+
- **default:** `false`
110+
- Split long text message to multiple messages.<br/>
111+
This is useful when you want to send a message longer than the maximum length allowed by Telegram.<br/>
112+
Available only with the `sendMessage` method. (It will returns an array of Message)<br/>
113+
Optional `reply_markup` parameter will be sent on last message.
114+
115+
### `logger`
116+
117+
- **type:** `Psr\Log\LoggerInterface`
118+
- **default:** `Psr\Log\NullLogger`
119+
- The logger used to log debug http requests.<br/>
120+
[Check out the Logging page for other info.](logging)
121+
122+
## IDE autocompletion
123+
124+
To enable IDE autocompletion, you can install the following plugin on your IDE:
125+
126+
### Plugin
127+
128+
- Jetbrains [deep-assoc-completion](https://plugins.jetbrains.com/plugin/9927-deep-assoc-completion)
129+
- Visual Studio
130+
Code [deep-assoc-completion-vscode](https://marketplace.visualstudio.com/items?itemName=klesun.deep-assoc-completion-vscode)
131+
132+
### Preview
133+
134+
![IDE autocompletion](https://i.imgur.com/mnsLRsZ.gif)

0 commit comments

Comments
 (0)