Mavzu: PHP dasturlash tilida Telegram bot yozish (INTERNET VA DASTURLASH/Dasturlash tillari) Kungaboqar (27 Sep 2018 08:59) PHP dasturlash tilida Telegram bot yozish shu haqida muhokama qilamiz bu orqali mukkammal saytlar yaratishimiz mumkun mendaham shu muamo bot qanday buyruq berib boshqarish! Yosh_Kitobxon (27 Sep 2018 09:01) Shu haqida kimda malumot bor Besthakker (27 Sep 2018 09:37) Saytdagi bot ni nazarda tutdizmi yoki telegramdagi botnimi Kungaboqar (27 Sep 2018 09:42) --Javob-- Besthakker (27 Sep 2018 09:37): Saytdagi bot ni nazarda tutdizmi yoki telegramdagi botnimi ---------- [b]Besthakker,[/b] Mavzu va 1postda yozilganku do`st Arey (27 Sep 2018 14:33) Yaxshi kerakli narsa. Kimda qanday ma'lumot bor.
[b]37 sekunddan so'ng qo'shdi...[/b]
Yaxshi kerakli narsa. Kimda qanday ma'lumot bor. Kungaboqar (27 Sep 2018 14:54) Bahh Tee bordir lekin yozarmikan u MoRGaN (27 Sep 2018 20:41) shuni video rolik qiberaman narmalni pul to'lolsa kmdir @morganbek botni kodini topadi lekin ishlatishni bilmaydiganlar uchun. phpni bilsa keyin uzi yozadi Brigand (28 Sep 2018 08:23) Men shu mavzudan keyin bot ochishga qiziqib net titkiladim. (oldin bilmasdim. Hozir örganib oldim.) phpda bot ochish uchun hostingdan akkaunt kerak. Chunki bot hostingdagi biror php faylga ulanadi va ösha php faylga kodlar yozilaveradi. Fayldagi kodlar botda ishlayveradi. Men server bilan botni ulay olmadim. Hozir bilganimni örgataman. Oldin tgda @botfather ga kiriladi. Keyin startni bosasiz. Keyin /newbot deb yozasiz. Yangi botni nomini yoz deydi. Masalan UzmasteS.Ru master forum deb yozasiz. Keyin botni manzilini yoz deydi. Manzil bot sözi bilan tugashi shart. Masalan uzmasters_bot Agar bu manzil band bölsa sorry bir narsalar deydi. Keyin uzmasters_forum_bot deb yozasiz. Bu manzil bösh bölsa bot ochildi deydi va sizga uzun kod beradi. raqamlar:katta-kichik harflar körinishida böladi kod. Keyin botni server bilan ulash uchun shu kodni hostingdagi php faylga yozish kerak. Keyin botga Hello deb yozilsa bot php fayldagi ködlarga köra javob berishi kerak. Men shu narsani qilolmayapman. Maqola forum uchun @Brigand tomonidan tayyorlandi. :)
[b]4290dan so'ng qo'shdi...[/b]
Hostingdagi php faylga bu kod yoziladi: [php]<?php
define('BOT_TOKEN', '12345678:yani botfather bergan kod');
define('API_URL', ' https://api.telegram.org/bo t'.BOT_TOKEN.'/');
function apiRequestWebhook($method, $parameters) {
if (!is_string($method)) {
error_log("Method name must be a string\\n");
return false;
}
if (!$parameters) {
$parameters = array();
} else if (!is_array($parameters)) {
error_log("Parameters must be an array\\n");
return false;
}
$parameters["method"] = $method;
header("Content-Type: application/json");
echo json_encode($parameters);
return true;
}
function exec_curl_request($handle) {
$response = curl_exec($handle);
if ($response === false) {
$errno = curl_errno($handle);
$error = curl_error($handle);
error_log("Curl returned error $errno: $error\\n");
curl_close($handle);
return false;
}
$http_code = intval(curl_getinfo($handle, CURLINFO_HTTP_CODE));
curl_close($handle);
if ($http_code >= 500) {
// do not wat to DDOS server if something goes wrong
sleep(10);
return false;
} else if ($http_code != 200) {
$response = json_decode($response, true);
error_log("Request has failed with error {$response['error_code']}: {$response['description']}\\n");
if ($http_code == 401) {
throw new Exception('Invalid access token provided');
}
return false;
} else {
$response = json_decode($response, true);
if (isset($response['description'])) {
error_log("Request was successful: {$response['description']}\\n");
}
$response = $response['result'];
}
return $response;
}
function apiRequest($method, $parameters) {
if (!is_string($method)) {
error_log("Method name must be a string\\n");
return false;
}
if (!$parameters) {
$parameters = array();
} else if (!is_array($parameters)) {
error_log("Parameters must be an array\\n");
return false;
}
foreach ($parameters as $key => &$val) {
// encoding to JSON array parameters, for example reply_markup
if (!is_numeric($val) && !is_string($val)) {
$val = json_encode($val);
}
}
$url = API_URL.$method.'?'.http_build_query($parameters);
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
return exec_curl_request($handle);
}
function apiRequestJson($method, $parameters) {
if (!is_string($method)) {
error_log("Method name must be a string\\n");
return false;
}
if (!$parameters) {
$parameters = array();
} else if (!is_array($parameters)) {
error_log("Parameters must be an array\\n");
return false;
}
$parameters["method"] = $method;
$handle = curl_init(API_URL);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($parameters));
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
return exec_curl_request($handle);
}
function processMessage($message) {
// process incoming message
$message_id = $message['message_id'];
$chat_id = $message['chat']['id'];
if (isset($message['text'])) {
// incoming text message
$text = $message['text'];
if (strpos($text, "/start") === 0) {
apiRequestJson("sendMessage", array('chat_id' => $chat_id, "text" => 'Hello', 'reply_markup' => array(
'keyboard' => array(array('Hello', 'Hi')),
'one_time_keyboard' => true,
'resize_keyboard' => true)));
} else if ($text === "Hello" || $text === "Hi") {
apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => 'Nice to meet you'));
} else if (strpos($text, "/stop") === 0) {
// stop now
} else {
apiRequestWebhook("sendMessage", array('chat_id' => $chat_id, "reply_to_message_id" => $message_id, "text" => 'Cool'));
}
} else {
apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => 'I understand only text messages'));
}
}
define('WEBHOOK_URL', ' http://saytingiz.uz/index.php/');
if (php_sapi_name() == 'cli') {
// if run from console, set or delete webhook
apiRequest('setWebhook', array('url' => isset($argv[1]) && $argv[1] == 'delete' ? '' : WEBHOOK_URL));
exit;
}
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (!$update) {
// receive wrong update, must not happen
exit;
}
if (isset($update["message"])) {
processMessage($update["message"]);[/php] MASTER_KHAMRAEV (4 Oct 2018 22:53) ??? MoRGaN (9 Nov 2018 22:42) Sayti borlar uchun vaqtni trafikni tejovchi qulay taklif:

Saytni telegram bilan birlashtiramiz botga mp3, maqola jo'natsangiz saytga joylaydi + kanalga ham!!!
Ishlash tartibi;
Mp3 - forward qilinadi (tag cover bosib joylaydi);
Maqola - *Maqola matni
*yoziladigan bo'lim id raqami
Shu tarzda ishlatish mumkin ideangizga qarab tayyorlab o'rnatib beriladi!
Aloqa: @morganbek / sh.x
Narxlar: ishga qarab 700rubldan boshlanadi! So'mda 100ming;
Namuna bor.-> Buyurtma bermoqchi bo'lganlar yozishi mumkin-> Fanat_FCB (9 Nov 2018 23:38) Telegramda numerni qanday uknown qilish mumkin qayerga yozishni bilmadim Hosting (13 Jan 2019 06:06) --Javob-- Fanat_FCB (9 Nov 2018 23:38): Telegramda numerni qanday uknown qilish mumkin qayerga yozishni bilmadim ---------- [b]Fanat_FCB,[/b] Mavzudan adashtiz :) okean (6 Feb 2019 14:25) urgatadganyumi Dambildor (24 Jun 2019 08:49) telegramda bit yaratishdi Urgatadigannbormi Shakhrukh (24 Jun 2019 08:54) [b]Dambildor,[/b] bor albatta. Qanday bot yaratish kerak. Botfather ga kirasiz u yerdan /newbot ni tanlaysiz bot nomini @* kiritasiz api manzil beradi shuni olasiz. php kodingiz bolsa botga api ni va admin id ni yozib qoyasiz hostingga joylab webhook qilasiz ok. MrSanjarbek (25 Jun 2019 17:30) Jmgjm DoN (9 Nov 2019 10:33) Bu borada Kimda Qanaqa Savol bor Bemalol Yozaverizlar Man Endi Urgandim va Urganishda davom Etoman Qoldan Kelgancha Yordam beraman Manba: https://www.uzmasters.ru/forum/6/27/2879/