-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbot.php
More file actions
39 lines (35 loc) · 1.03 KB
/
bot.php
File metadata and controls
39 lines (35 loc) · 1.03 KB
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
<?php
require "token.php";
function curlRequest($url, $data = [])
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if (!empty($data)) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
function sm($chat_id, $text)
{
global $api;
$args = [];
if (empty($chat_id) || empty($text)) {
return false;
}
$args['chat_id'] = $chat_id;
$args['text'] = $text;
curlRequest('https://api.telegram.org/'.$api.'/sendMessage', $args);
}
$content = file_get_contents("php://input");
$update = json_decode($content, true);
unset($content);
if ($update['message']['photo']) {
sm($update['message']['chat']['id'], "$baseUrl?file_id=".$update['message']['photo'][count($update['message']['photo'])-1]['file_id']);
} else {
sm($update['message']['chat']['id'], "Mandami una foto");
}