-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.php
50 lines (35 loc) · 1.48 KB
/
bot.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
<?php
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\Drivers\Telegram\TelegramDriver;
require_once 'vendor/autoload.php';
date_default_timezone_set('Asia/Jakarta');
$configs = [
"telegram" => [
"token" => file_get_contents("private/BOT_TOKEN.txt")
]
];
DriverManager::loadDriver(TelegramDriver::class);
$botman = BotManFactory::create($configs);
$botman->hears("/start", function (BotMan $bot) {
$user = $bot->getUser();
$firstname = $user->getFirstName();
$bot->reply("Hi $firstname 😊, Makanan Apa Yang Ingin Diklasifikasi ?" . PHP_EOL . "/check {Isi URL} - Untuk Memulai Klasifikasi" . PHP_EOL . "\n*Pastikan /check {URL} -> pada alamat url mempunyai link berakhiran .jpg / .png. / .jpeg");
});
$botman->hears("/check {url}", function (BotMan $bot, $url){
require_once 'functions/getter.php';
require_once 'functions/IBM_API.php';
$classification = classifyImage($url);
$message = getMessage($classification->result, $classification->score);
$bot->reply($message);
});
$botman->hears("/help", function (BotMan $bot) {
$bot->reply("Bot Ini Digunakan Untuk Mengklasifikasikan Gambar Makanan" . PHP_EOL .
"/check {url} - Digunakan Untuk Mengklasifikasikan Gambar Makanan");
});
$botman->fallback(function (BotMan $bot) {
$message = $bot->getMessage()->getText();
$bot->reply("Maaf, Perintah Ini '$message' Tidak Ada/Kurang 😥");
});
$botman->listen();