ilk önce telegram uygulamasını indirin ve webden giriş yapın.
https://web.telegram.org/
daha sonra https://web.telegram.org/#/im?p=@BotFather botfathera bağlanıyoruz. adamlar bizim bot yapacağımızı bildiğinden bize bot yapma botu yapmışlar. evet bunu da yaptılar.
bu çocuğa ilk diyoruz /newbot sonra o bize diyor isim ver veriyoruz sonra bi daha isim istiyor fakat sonunda _bot olacak şekilde veriyoruz ve bize bir anahtar veriyor. search kısmından botumuzu arıyoruz ve ona bir şeyler yazıyoruz. sonra aşağıdaki linke giriyoruz.
1 2 3 |
https://api.telegram.org/bot{token bilgisini giriyoruz}/getUpdates örn : https://api.telegram.org/bot1028492955:AAGa6L0glytHusLt8y3S6zPDYX2ep2_lFpk/getUpdates |
oradaki linkte bota yazılan mesaj olup olmadığına bakıyoruz. tabi biz yazdık. hemen oradan from->id kısmındaki id’yi alıyoruz. bu bota yazan kişinin id’si. buna mesaj göndereceğimiz için bu id’ye ihtiyacımız var.
mesaj göndermek için:
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php $token = "1028492912:AAGa6L0glytHusLt6y3S6zPDYX2ep6_lFpk"; $user_id = "1058079453"; $msg = "selam deneme mesajı"; $request_params = [ 'chat_id' => $user_id, 'text' => $msg ]; $request_url = 'https://api.telegram.org/bot'.$token.'/sendMessage?'.http_build_query($request_params); echo file_get_contents($request_url); ?> |
fotoğraf göndermek için:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
$token = "1028492914:AAGa6L0glytHusLt8y3D4zPDYX2ep6_lFpk"; $user_id = "1058079203"; $msg = "a.jpg"; $request_params = [ 'chat_id' => $user_id, 'photo' => $msg ]; define('BOTAPI','https://api.telegram.org/bot' . $token .'/'); $cfile = new CURLFile(realpath('a.jpg'), 'image/jpg', 'a.jpg'); //first parameter is YOUR IMAGE path $data = [ 'chat_id' => $user_id , 'photo' => $cfile ]; $ch = curl_init(BOTAPI.'sendPhoto'); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); curl_close($ch); |