SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | $token = "111111111:xxxxxxxxxxxxxxxxxxxxxxxxxx"; | |
3 | $content=file_get_contents("php://input"); | |
4 | $content = json_decode($content,TRUE); | |
5 | $message = $content["message"]["text"]; | |
6 | $from = $content["message"]["from"]["id"]; | |
7 | ||
8 | if($message == '/start'){ | |
9 | $response = "Hi there :) \n example bot hax.co.id"; | |
10 | }elseif($message == '/getid'){ | |
11 | $response = "Your telegram ID is:".$from; | |
12 | }elseif($message == '/getchatid') { | |
13 | $response = "Your Chat ID is:".$content["message"]["chat"]["id"]; | |
14 | } | |
15 | ||
16 | $params = array( | |
17 | 'chat_id' => $content["message"]["chat"]["id"], | |
18 | 'text' => $response, | |
19 | 'action' => 'typing' | |
20 | ); | |
21 | ||
22 | $url = 'https://api.telegram.org/bot'.$token."/sendMessage"; | |
23 | $ch = curl_init(); | |
24 | curl_setopt($ch, CURLOPT_POST,1); | |
25 | curl_setopt($ch, CURLOPT_POSTFIELDS,$params); | |
26 | curl_setopt($ch, CURLOPT_URL,$url); | |
27 | curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); | |
28 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
29 | $result=curl_exec ($ch); |