电报机器人发送文件和文本PHP
我已经建立了一个基本的机器人程序,可以将文本发送回用户,现在我还想向用户发送一条音频消息。但我不能这样做,这是代码。电报机器人发送文件和文本PHP,php,telegram-bot,Php,Telegram Bot,我已经建立了一个基本的机器人程序,可以将文本发送回用户,现在我还想向用户发送一条音频消息。但我不能这样做,这是代码。 我也用这个来发送音频 include("Telegram.php); define('BOT_TOKEN', 'tokentoken'); define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/'); $telegram = new Telegram(BOT_TOKEN); $
我也用这个来发送音频
include("Telegram.php);
define('BOT_TOKEN', 'tokentoken');
define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
$telegram = new Telegram(BOT_TOKEN);
$content = file_get_contents("php://input");
$update = json_decode($content, true);
$chatID = $update["message"]["chat"]["id"];
$message = $update["message"]["text"];
$reply = sendMessage($message);
$sendto =API_URL."sendmessage?chat_id=".$chatID."&text=".$reply;
file_get_contents($sendto);
function sendMessage(&$string) {
switch ($string) {
case "Hi":
$message = "Hi Back";
sendAudio();
break;
case "Bye":
$message = "Bye Bye";
break;
default:
$message = "Default";
}
return $message
}
func sendAudio() {
$sound = curl_file_create('sampleAudio.mp3', 'audio/mp3');
$newContent = array('chat_id' => $chatID, 'audio' => $sound);
$telegram->sendAudio($newContent);
}
在函数外部调用代码是可行的,但是用户每次键入内容时都会得到文件。我正在做实验,所以稍微解释一下就好了。您有一些错误:
- “第一行”未关闭
- 最后一个函数,您键入的是“func”而不是“function”
- 在sendAudio()中,您使用了$chatID,但必须将其作为sendAudio()的参数传递,或者将其设置为全局
- “第一行”未关闭
- 最后一个函数,您键入的是“func”而不是“function”
- 在sendAudio()中,您使用了$chatID,但必须将其作为sendAudio()的参数传递,或者将其设置为全局
- 您有一些错误: