Skip to content

Commit 606cf12

Browse files
committed
README UPDATE
1 parent 2ba5c48 commit 606cf12

File tree

1 file changed

+122
-69
lines changed

1 file changed

+122
-69
lines changed

README.md

Lines changed: 122 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,69 @@
11
# PHP Telegram Bot
22
======================
33

4-
[![Join the chat at https://gitter.im/akalongman/php-telegram-bot](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/akalongman/php-telegram-bot?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4+
[![Join the chat at
5+
https://gitter.im/akalongman/php-telegram-bot](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/akalongman/php-telegram-bot?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
56

67
[![Build Status](https://travis-ci.org/akalongman/php-telegram-bot.svg?branch=master)](https://travis-ci.org/akalongman/php-telegram-bot)
7-
[![Latest Stable Version](https://img.shields.io/packagist/v/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot)
8+
[![Latest Stable
9+
Version](https://img.shields.io/packagist/v/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot)
810
[![Total Downloads](https://img.shields.io/packagist/dt/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot)
911
[![Downloads Month](https://img.shields.io/packagist/dm/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot)
1012
[![License](https://img.shields.io/packagist/l/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot)
1113

1214

13-
A Telegram Bot based on the official [Telegram Bot API](https://core.telegram.org/bots/api)
15+
A Telegram Bot based on the official [Telegram Bot
16+
API](https://core.telegram.org/bots/api)
1417

1518

16-
## Introduction
17-
This is a pure php Telegram Bot, fully extensible via plugins. Telegram recently announced official support for a [Bot API](https://telegram.org/blog/bot-revolution) allowing integrators of all sorts to bring automated interactions to the mobile platform. This Bot aims to provide a platform where one could simply write a plugin and have interactions in a matter of minutes.
18-
The Bot supports Reply Markup and handle commands in group chat with multiple bot.
19+
### Introduction
20+
This is a pure php Telegram Bot, fully extensible via plugins.
21+
Telegram recently announced official support for a [Bot
22+
API](https://telegram.org/blog/bot-revolution) allowing integrators of
23+
all sorts to bring automated interactions to the mobile platform. This
24+
Bot aims to provide a platform where one could simply write a plugin
25+
and have interactions in a matter of minutes.
26+
- The Bot supports Reply Markup and handle commands in group chat with
27+
multiple bot.
28+
- The Bot can retrive update with webhook and by getUpdate methods.
1929

2030

21-
Instructions
22-
============
31+
## Instructions
32+
### Create your first bot
2333

24-
1. Message @botfather https://telegram.me/botfather with the following text: `/newbot`
25-
If you don't know how to message by username, click the search field on your Telegram app and type `@botfather`, you should be able to initiate a conversation. Be careful not to send it to the wrong contact, because some users has similar usernames to `botfather`.
34+
1. Message @botfather https://telegram.me/botfather with the following
35+
text: `/newbot`
36+
If you don't know how to message by username, click the search
37+
field on your Telegram app and type `@botfather`, you should be able
38+
to initiate a conversation. Be careful not to send it to the wrong
39+
contact, because some users has similar usernames to `botfather`.
2640

2741
![botfather initial conversation](http://i.imgur.com/aI26ixR.png)
2842

29-
2. @botfather replies with `Alright, a new bot. How are we going to call it? Please choose a name for your bot.`
43+
2. @botfather replies with `Alright, a new bot. How are we going to
44+
call it? Please choose a name for your bot.`
3045

3146
3. Type whatever name you want for your bot.
3247

33-
4. @botfather replies with `Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: TetrisBot or tetris_bot.`
48+
4. @botfather replies with `Good. Now let's choose a username for your
49+
bot. It must end in `bot`. Like this, for example: TetrisBot or
50+
tetris_bot.`
3451

35-
5. Type whatever username you want for your bot, minimum 5 characters, and must end with `bot`. For example: `telesample_bot`
52+
5. Type whatever username you want for your bot, minimum 5 characters,
53+
and must end with `bot`. For example: `telesample_bot`
3654

3755
6. @botfather replies with:
3856

39-
Done! Congratulations on your new bot. You will find it at telegram.me/telesample_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands.
57+
Done! Congratulations on your new bot. You will find it at
58+
telegram.me/telesample_bot. You can now add a description, about
59+
section and profile picture for your bot, see /help for a list of
60+
commands.
4061

4162
Use this token to access the HTTP API:
4263
<b>123456789:AAG90e14-0f8-40183D-18491dDE</b>
4364

44-
For a description of the Bot API, see this page: https://core.telegram.org/bots/api
65+
For a description of the Bot API, see this page:
66+
https://core.telegram.org/bots/api
4567

4668
7. Note down the 'token' mentioned above.
4769

@@ -51,27 +73,28 @@ Instructions
5173

5274
9. @botfather replies with `Choose a bot to change group messages settings.`
5375

54-
10. Type `@telesample_bot` (change to the username you set at step 5 above, but start it with `@`)
76+
10. Type `@telesample_bot` (change to the username you set at step 5
77+
above, but start it with `@`)
5578

5679
11. @botfather replies with
5780

58-
'Enable' - your bot will only receive messages that either start with the '/' symbol or mention the bot by username.
81+
'Enable' - your bot will only receive messages that either start
82+
with the '/' symbol or mention the bot by username.
5983
'Disable' - your bot will receive all messages that people send to groups.
6084
Current status is: ENABLED
6185

62-
12. Type `Disable` to let your bot receive all messages sent to a group. This step is up to you actually.
86+
12. Type `Disable` to let your bot receive all messages sent to a
87+
group. This step is up to you actually.
6388

6489
13. @botfather replies with `Success! The new status is: DISABLED. /help`
6590

6691

92+
### Require this package with Composer
93+
Install this package through [Composer](https://getcomposer.org/).
94+
Edit your project's `composer.json` file to require
95+
`longman/telegram-bot`.
6796

68-
69-
## Installation
70-
You need server with https and composer support.
71-
72-
Install this package through [Composer](https://getcomposer.org/). Edit your project's `composer.json` file to require `longman/telegram-bot`.
73-
74-
Create composer.json file:
97+
Create *composer.json* file:
7598
```js
7699
{
77100
"name": "yourproject/yourproject",
@@ -90,14 +113,20 @@ And run composer update
90113
composer require longman/telegram-bot
91114
```
92115

93-
###### Bot token
94-
You will notice that the Telegram Bot wants a value for `API_KEY`. This token may be obtained via a telegram client for your bot. See [this](https://core.telegram.org/bots#botfather) link if you are unsure of how to so this.
116+
### Choose how to retrieve Telegram updates
117+
The bot can handle updates with **webhook** or **getUpdate** method:
95118

119+
| Method | Webhook | getUpdate |
120+
| ---- | :----: | :----: |
121+
| Description | Telegram send the update directy to your host | Yuo
122+
have to fetch Telegram updates |
123+
| Host with https | Required | Not required |
124+
| Mysql | Not required | Required |
96125

97-
## Usage
126+
## Webhook installation
127+
You need server with https and composer support.
98128
You must set a [WebHook](https://core.telegram.org/bots/api#setwebhook)
99-
100-
Create set.php and put into it:
129+
Create *set.php* (just edit *example-set.php*) and put into it:
101130
```php
102131
<?php
103132
$loader = require __DIR__.'/vendor/autoload.php';
@@ -114,10 +143,10 @@ try {
114143
echo $e->getMessage();
115144
}
116145
```
117-
And open your set.php via browser
146+
And open your *set.php* via browser.
118147

119148

120-
After create hook.php and put:
149+
After create *hook.php* (just edit *example-hook.php*) and put:
121150
```php
122151
<?php
123152
$loader = require __DIR__.'/vendor/autoload.php';
@@ -127,9 +156,7 @@ $BOT_NAME = 'namebot';
127156

128157
try {
129158
// create Telegram API object
130-
$telegram = new Longman\TelegramBot\Telegram($API_KEY,$BOT_NAME);
131-
// here you can set some command specified parameters, for example, google geocode/timezone api key for date command:
132-
$telegram->setCommandConfig('date', array('google_api_key'=>'your_google_api_key_here'));
159+
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
133160

134161
// handle telegram webhook request
135162
$telegram->handle();
@@ -138,25 +165,44 @@ try {
138165
// echo $e->getMessage();
139166
}
140167
```
168+
## getUpdate installation NEW!
169+
You need the database Mysql active.
141170

142-
##MySQL storage
143-
If you want insert in database messages/users for further usage in commands, create database and import structure.sql and enable mysql support after object creation and BEFORE handle method
171+
Create *getUpdateCLI.php* (just edit *example-getUpdateCLI.php*) and
172+
put into it:
173+
```php
174+
code
175+
```
176+
give to the file the permission for execution:
177+
```
178+
chmod 775 getUpdateCLI.php
179+
```
180+
then run
181+
```
182+
./getUpdateCLI.php
183+
```
184+
## Utilis
185+
### MySQL storage (Recomended)
186+
If you want insert in database messages/users/chats for further usage
187+
in commands, create database and import *structure.sql* and enable
188+
Mysql support after object creation and BEFORE handle method:
144189

145190
```php
146-
<?php
147-
$credentials = array('host'=>'localhost', 'user'=>'dbuser', 'password'=>'dbpass', 'database'=>'dbname');
191+
192+
$credentials = array('host'=>'localhost', 'user'=>'dbuser',
193+
'password'=>'dbpass', 'database'=>'dbname');
148194

149195
$telegram->enableMySQL($credentials);
150196
```
151-
You can set a custom prefix to all the tables while you are enabling mysql:
197+
You can set a custom prefix to all the tables while you are enabling Mysql:
152198

153199
```php
154200
$telegram->enableMySQL($credentials, $BOT_NAME.'_');
155-
156201
```
157202

158-
##Commands
159-
The bot is able to recognise commands in chat with multiple bot.
203+
### Commands
204+
The bot is able to recognise commands in chat with multiple bot(
205+
/command@mybot ).
160206
It can execute command triggering a chat event. Here's the list:
161207

162208
- Group chat created (**GroupchatcreatedCommand.php**)
@@ -165,38 +211,47 @@ It can execute command triggering a chat event. Here's the list:
165211
- New chat title (**NewchattitleCommand.php**)
166212
- Left chat participant (**LeftchatparticipantCommand.php**)
167213

168-
**GenericCommand.php** lets you handle commands that don't exist or to use commands as a variable:
214+
**GenericCommand.php** lets you handle commands that don't exist or to
215+
use commands as a variable:
169216
Favourite colour? **/black, /red**
170217
Favourite number? **/1, /134**
171218

172-
173-
Maybe you would like to develop your own commands. A good practice is to store them outside vendor/. This can be done adding the method:
219+
Maybe you would like to develop your own commands. A good practice is
220+
to store them outside vendor/. This can be done adding the method:
174221

175222
```php
176223
$COMMANDS_FOLDER = __DIR__.'/Commands/';
177224
$telegram->addCommandsPath($COMMANDS_FOLDER);
178-
179225
```
180226

181-
##Admin Commands (new!)
182-
Enabling this feature, the admin bot can perform some super user command like send message to all.
227+
### Admin Commands (new!)
228+
Enabling this feature, the admin bot can perform some super user
229+
command like send message to all.
183230
You can specify one or more admin with this option:
184231

185232
```php
186233
$telegram->enableAdmins(array('TelegramUserID','Othersid'));
187234
```
188-
Telegram user id can be retrieved with the command /whoami.
189-
Admin commands are stored in src/Admin/ folder.
190-
To know all the commands avaiable type /help.
235+
Telegram user id can be retrieved with the command **/whoami**.
236+
Admin commands are stored in *src/Admin/* folder.
237+
To know all the commands avaiable type **/help**.
191238

192-
##Send message to all active chats
193-
To do this you have to enable the mysql connection.
239+
### Commands Configuration
240+
With this method you can set some command specified parameters, for
241+
example, google geocode/timezone api key for date command:
242+
```php
243+
$telegram->setCommandConfig('date',
244+
array('google_api_key'=>'your_google_api_key_here'));
245+
```
246+
### Send message to all active chats
247+
To do this you have to enable the Mysql connection.
194248
Here's an example of use:
195249

196250
```php
197251
$results = $telegram->sendToActiveChats(
198252
'sendMessage', //callback function to execute (see Request.php methods)
199-
array('text'=>'Hey! Checkout the new feature!!'), //Param to evaluate the request
253+
array('text'=>'Hey! Checkout the new feature!!'), //Param to
254+
evaluate the request
200255
true, //Send to chats (group chat)
201256
true, //Send to users (single chat)
202257
null, //'yyyy-mm-dd hh:mm:ss' date range from
@@ -206,28 +261,26 @@ $results = $telegram->sendToActiveChats(
206261
print_r($results);
207262
```
208263

209-
##Utilis
210-
You can also log incoming messages on a text file, set this option with the methods:
264+
### Logging
265+
You can also log incoming messages on a text file, set this option
266+
with the methods:
211267
```php
212268
$telegram->setLogRequests(true);
213269
$telegram->setLogPath($BOT_NAME.'.log');
214-
215270
```
271+
-----
216272

217-
This code is available on [Github](https://github.com/akalongman/php-telegram-bot). Pull requests are welcome.
218273

274+
This code is available on
275+
[Github](https://github.com/akalongman/php-telegram-bot). Pull
276+
requests are welcome.
219277

220-
##Troubleshooting
221-
222-
If you like living on the edge, please report any bugs you find on the [PHP Telegram Bot issues](https://github.com/akalongman/php-telegram-bot/issues) page.
223-
224-
225-
##Contributing
226-
278+
## Troubleshooting
279+
If you like living on the edge, please report any bugs you find on the
280+
[PHP Telegram Bot
281+
issues](https://github.com/akalongman/php-telegram-bot/issues) page.
282+
## Contributing
227283
See [CONTRIBUTING.md](CONTRIBUTING.md) for information.
228-
229-
230284
## Credits
231285

232286
Credit list in [CREDITS](CREDITS)
233-

0 commit comments

Comments
 (0)