-
Notifications
You must be signed in to change notification settings - Fork 1
/
tele_index.php
78 lines (70 loc) · 2.52 KB
/
tele_index.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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require __DIR__ . '/vendor/autoload.php';
use SergiX44\Nutgram\Nutgram;
use SergiX44\Nutgram\RunningMode\Webhook;
use SergiX44\Nutgram\Telegram\Types\Keyboard\ForceReply;
require_once("env.php");
require_once("helper/mysql-helper.php");
require_once("helper/helper-general.php");
$db = new DataBase($_ENV['db_host'], 3306, $_ENV['db_user'], $_ENV['db_password'], $_ENV['db_name']);
$bot = new Nutgram($_ENV['token']);
$bot->setRunningMode(Webhook::class);
$bot->onCommand('start', function (Nutgram $bot) {
$bot->sendMessage(
text: 'balas dengan harga target!',
reply_to_message_id: $bot->message()->message_id,
reply_markup: ForceReply::make(
force_reply: true,
input_field_placeholder: '300000',
selective: true,
),
);
});
$bot->onMessage(function (Nutgram $bot) {
try {
global $db;
$text = $bot->message()->text;
$response = file_get_contents('php://input');
$jsonData = json_decode($response);
if ($jsonData !== null) {
$prettifiedResponse = '<pre>' . json_encode($jsonData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . '</pre>';
} else {
$prettifiedResponse = 'Invalid JSON format';
}
// $bot->sendMessage($prettifiedResponse, null, null, "HTML");
if (filter_var($text, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)) {
$url = $text;
$sender_id = $bot->userId();
$unique_id = generateRandomCode();
$data = [
'unique_id' => $unique_id,
'link_tokped' => $url,
'sender_id' => $sender_id
];
$db->insert('link_data', $data);
$bot->sendMessage(
"Sukses disimpan dengan ID " . $unique_id . "\nbalas dengan harga target anda",
reply_to_message_id: $bot->message()->message_id,
reply_markup: ForceReply::make(
force_reply: true,
selective: true
),
);
} else if (str_contains($bot->message()->reply_to_message->text ?? "", "balas dengan harga target anda")) {
$id_unique = extractID($bot->message()->reply_to_message->text);
$text = $bot->message()->text;
$db->update('link_data', ['harga_target' => $text], 'unique_id', $id_unique);
$bot->sendMessage("berhasil " . $id_unique);
} else {
$bot->sendMessage('sorry I don\'t understand');
// $bot->sendMessage(json_encode($bot->message()));
}
} catch (Exception $e) {
$bot->sendMessage(json_encode($e->getMessage()));
}
});
$bot->run();
echo "Bot is running";