forked from radyakaze/phptelebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.php
83 lines (66 loc) · 1.94 KB
/
sample.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
require_once __DIR__.'/src/PHPTelebot.php';
$bot = new PHPTelebot('TOKEN', 'BOT_USERNAME');
// Simple answer
$bot->cmd('*', 'Hi, human! I am a bot.');
// Simple echo command
$bot->cmd('/echo|/say', function ($text) {
if ($text == '') {
$text = 'Command usage: /echo [text] or /say [text]';
}
return Bot::sendMessage($text);
});
// Simple whoami command
$bot->cmd('/whoami', function () {
// Get message properties
$message = Bot::message();
$name = $message['from']['first_name'];
$userId = $message['from']['id'];
$text = 'You are <b>'.$name.'</b> and your ID is <code>'.$userId.'</code>';
$options = [
'parse_mode' => 'html',
'reply' => true,
];
return Bot::sendMessage($text, $options);
});
// slice text by space
$bot->cmd('/split', function ($one, $two, $three) {
$text = "First word: $one\n";
$text .= "Second word: $two\n";
$text .= "Third word: $three";
return Bot::sendMessage($text);
});
// simple file upload
$bot->cmd('/upload', function () {
$file = './composer.json';
return Bot::sendDocument($file);
});
// inline keyboard
$bot->cmd('/keyboard', function () {
$keyboard[] = [
['text' => 'PHPTelebot', 'url' => 'https://github.com/radyakaze/phptelebot'],
['text' => 'Haru bot', 'url' => 'https://telegram.me/harubot'],
];
$options = [
'reply_markup' => ['inline_keyboard' => $keyboard],
];
return Bot::sendMessage('Inline keyboard', $options);
});
// custom regex
$bot->regex('/\/number ([0-9]+)/i', function ($matches) {
return Bot::sendMessage($matches[1]);
});
// Inline
$bot->on('inline', function ($text) {
$results[] = [
'type' => 'article',
'id' => 'unique_id1',
'title' => $text,
'message_text' => 'Lorem ipsum dolor sit amet',
];
$options = [
'cache_time' => 3600,
];
return Bot::answerInlineQuery($results, $options);
});
$bot->run();