PHP Aiutatemi! non funziona il bot di telegram

jesus.italy666

Utente Iron
19 Aprile 2019
2
1
0
14
Ciao a tutti, sono nuovo su questo forum ma un amico mi ha detto che mi avreste sicuramente aiutato con il mio problema.

Stò cercando di imparare ad usare il php per creare dei bot per telegram, ma ogni volta che provo a far funzionare il bot fallisco miseramente.

Ho creato due file uno è l'index.php e l'altro è il source.php nell'index.php ho scritto determinate stringhe:
Codice:
<?php

include source.php;

if($testo == 'hey'){
  sendMsg($cId, 'bot test');
}


?>

mentre nel source.php ho scritto determinato codice:
Codice:
<?php

//variabili importanti bot
$botToken = "TOKEN(scritto così per non avere problemi)";
$site = "https://api.telegram.org/bot".$botToken;"/";

$update = file_get_content('php://input');
$update = json_encode($update, true);

//variabili

$msg = $update['message'];
$cId = $update['message']['chat']['id'];
$testo = $update['message']['text'];


//function area

function sendMsg($cId,$testo){
  $url = $site."sendMessage/chat_id=".$cId."&parse_mode=HTML&text".urlencode($testo);
  file_get_content($url);
}



?>
 
PHP:
<?php
    $token = "";
    $url = "https://api.telegram.org/bot" . $token;
    $update = json_decode(file_get_contents('php://input') ,true);
    $chat_id = $update['message']['chat']['id'];
    $name = $update['message']['from']['first_name'];
    $message = 'Ciao '.$name;
    file_get_contents($url . "/sendmessage?text=" . $message . "&chat_id=" . $chat_id);
?>
 
PHP:
<?php
    $token = "";
    $url = "https://api.telegram.org/bot" . $token;
    $update = json_decode(file_get_contents('php://input') ,true);
    $chat_id = $update['message']['chat']['id'];
    $name = $update['message']['from']['first_name'];
    $message = 'Ciao '.$name;
    file_get_contents($url . "/sendmessage?text=" . $message . "&chat_id=" . $chat_id);
?>
ok, mancano tante variabili e vorrei fare delle funzioni comunque questo codice non sembra funzionare
 
Se stai usando altervista credo che tu debba attivare la connessione server to server dalle impostazioni di PHP