You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://gitter.im/akalongman/php-telegram-bot?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
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)
14
17
15
18
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.
19
29
20
30
21
-
Instructions
22
-
============
31
+
## Instructions
32
+
### Create your first bot
23
33
24
-
1. Message @botfatherhttps://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 @botfatherhttps://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`.
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.`
30
45
31
46
3. Type whatever name you want for your bot.
32
47
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.`
34
51
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`
36
54
37
55
6.@botfather replies with:
38
56
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.
40
61
41
62
Use this token to access the HTTP API:
42
63
<b>123456789:AAG90e14-0f8-40183D-18491dDE</b>
43
64
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
45
67
46
68
7. Note down the 'token' mentioned above.
47
69
@@ -51,27 +73,28 @@ Instructions
51
73
52
74
9.@botfather replies with `Choose a bot to change group messages settings.`
53
75
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 `@`)
55
78
56
79
11.@botfather replies with
57
80
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.
59
83
'Disable' - your bot will receive all messages that people send to groups.
60
84
Current status is: ENABLED
61
85
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.
63
88
64
89
13.@botfather replies with `Success! The new status is: DISABLED. /help`
65
90
66
91
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`.
67
96
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:
75
98
```js
76
99
{
77
100
"name":"yourproject/yourproject",
@@ -90,14 +113,20 @@ And run composer update
90
113
composer require longman/telegram-bot
91
114
```
92
115
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:
95
118
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 |
96
125
97
-
## Usage
126
+
## Webhook installation
127
+
You need server with https and composer support.
98
128
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:
101
130
```php
102
131
<?php
103
132
$loader = require __DIR__.'/vendor/autoload.php';
@@ -114,10 +143,10 @@ try {
114
143
echo $e->getMessage();
115
144
}
116
145
```
117
-
And open your set.php via browser
146
+
And open your *set.php* via browser.
118
147
119
148
120
-
After create hook.php and put:
149
+
After create *hook.php* (just edit *example-hook.php*) and put:
121
150
```php
122
151
<?php
123
152
$loader = require __DIR__.'/vendor/autoload.php';
@@ -127,9 +156,7 @@ $BOT_NAME = 'namebot';
127
156
128
157
try {
129
158
// 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:
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
133
160
134
161
// handle telegram webhook request
135
162
$telegram->handle();
@@ -138,25 +165,44 @@ try {
138
165
// echo $e->getMessage();
139
166
}
140
167
```
168
+
## getUpdate installation NEW!
169
+
You need the database Mysql active.
141
170
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:
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
0 commit comments