-
Notifications
You must be signed in to change notification settings - Fork 13
/
msg_processing_simple.php
58 lines (52 loc) · 1.43 KB
/
msg_processing_simple.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/*
* Telegram Bot Sample
* ===================
* UWiClab, University of Urbino
* ===================
* Basic message processing functionality,
* used by both pull and push scripts.
*
* Put your custom bot intelligence here!
*/
// This file assumes to be included by pull.php or
// hook.php right after receiving a new message.
// It also assumes that the message data is stored
// inside a $message variable.
// Message object structure: {
// "message_id": 123,
// "from": {
// "id": 123456789,
// "first_name": "First",
// "last_name": "Last",
// "username": "FirstLast"
// },
// "chat": {
// "id": 123456789,
// "first_name": "First",
// "last_name": "Last",
// "username": "FirstLast",
// "type": "private"
// },
// "date": 1460036220,
// "text": "Text"
// }
$message_id = $message['message_id'];
$chat_id = $message['chat']['id'];
$from_id = $message['from']['id'];
if (isset($message['text'])) {
// We got an incoming text message
$text = $message['text'];
if (strpos($text, "/start") === 0) {
echo 'Received /start command!' . PHP_EOL;
telegram_send_message($chat_id, 'This is your first Telegram bot, welcome!');
}
else {
echo "Received message: $text" . PHP_EOL;
// Do something else...
}
}
else {
telegram_send_message($chat_id, 'Sorry, I understand only text messages at the moment!');
}
?>