我正在开发一个Telegram机器人,我想使用Webhooks而不是轮询来从Telegram服务器获取消息.
我正在开发和测试localhost上的应用程序,该应用程序不是可访问的Web主机,因此我无法将其设置为Webhook URL.
现在我想知道如何通过Webhooks在本地机器上从Telegram获得真正的消息?
我需要用我的Telegram Bot发送包含表情符号的消息.
所以我复制/粘贴表情符号代码:nine:
,例如,在我的消息文本中,并将其发送给用户,但表情符号没有工作.
这是我的示例代码和函数:
function tel_send($key, $t, $c)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.telegram.org/bot" . $key . "/sendMessage");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "cache=" . (time() / rand(1, time() - 100)) . "&text=" . $t . "&chat_id=" . $c);
$ss = curl_exec($ch);
curl_close($ch);
return $ss;
}
tel_send($key, "My number - :nine:", $val['message']['chat']['id']);
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是:我如何通过Telegram bot发送表情符号?
我正在尝试将结构转换为地图,以便能够清除所有的nil值
我目前正在使用此代码
case Nadia.get_updates do
{:ok, results} ->
Map.from_struct(results)
|> Enum.filter(fn {_, v} -> v != nil end)
|> Enum.into(%{})
Run Code Online (Sandbox Code Playgroud)
注意:Nadia.get_updates返回以下结构:https://hexdocs.pm/nadia/Nadia.Model.Update.html#t:t / 0
然而,我总是收到以下错误:Map.from_struct/1中没有匹配的函数子句
我用电报创建了一个机器人
我想将带有HTML页面的粗体和斜体文本发送到bot
我的HTML代码是:
<html>
<head><title>Telegram</title></head>
<body>
<form method="GET" action="https://api.telegram.org/bot(token)/sendMessage">
<input type="hidden" name="chat_id" value="@testadminch">
<input type="hidden" name="parse_mod" value="markdown">
<textarea name="text"></textarea>
<input type="submit" value="Submit">
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果我发送*bold*
输出应该是粗体但它不起作用
我想知道删除邮件或文件的示例,如照片
我没有找到这方面的任何功能性教程,
为什么我的webhook无法正常工作?我没有从电报bot API获得任何数据.这是我的问题的详细解释:
我从StartSSL获得SSL证书,它在我的网站上工作正常(根据GeoCerts SSL检查器),但似乎我的webhook到Telegram Bot API不起作用(尽管它说webhook设置我没有得到任何数据) .
我正在以这种形式在我的网站上制作一个webhook到我的脚本:
https://api.telegram.org/bot<token>/setWebhook?url=https://mywebsite.com/path/to/giveawaysbot.php
Run Code Online (Sandbox Code Playgroud)
我得到这个文本作为回应:
{"ok":true,"result":true,"description":"Webhook was set"}
Run Code Online (Sandbox Code Playgroud)
所以它必须有效,但实际上并非如此.
这是我的脚本代码:
<?php
ini_set('error_reporting', E_ALL);
$botToken = "<token>";
$website = "https://api.telegram.org/bot".$botToken;
$update = file_get_contents('php://input');
$update = json_decode($update);
print_r($update); // this is made to check if i get any data or not
$chatId = $update["message"]["chat"]["id"];
$message = $update["message"]["text"];
switch ($message) {
case "/test":
sendMessage($chatId,"test complete");
break;
case "/hi":
sendMessage($chatId,"hey there");
break;
default:
sendMessage($chatId,"nono i dont understand you");
}
function sendMessage ($chatId, $message) …
Run Code Online (Sandbox Code Playgroud) 所以我发现我可以在 HTML 中使用这样的链接:
<a href="https://api.whatsapp.com/send?phone={{phone_number}}" target="_blank">WhatsApp</a>
Run Code Online (Sandbox Code Playgroud)
为了让用户{{phone_number}}
直接从网页(通过 WhatsApp 网页)联系。
我的问题是:如何通过 Telegram 做同样的事情而不是 WhatsApp?
先感谢您
电报机器人可以读取/访问我或机器人既不是管理员的电报频道吗?
我知道直到去年11月才有可能,但我听说有些人已经这样做了,但到目前为止我无法做到.
我非常感谢您的投入和知识.
Ps任何解决方法都会很棒.
我正在尝试使用自定义键盘在PHP中创建一个Telgram Bot.邮件已发送,但自定义键盘无法使用.$ keyb = array('keyboard'=> array(array("A","B"))); 也没有成功.
所述的sendMessage方法引荐ReplyKeyboardMarkup为对象.为ReplyKeyboardMarkup创建数组不起作用.还尝试了json_encode($ keyb),但这也不是解决方案.
我在GitHub中搜索了一些示例,但我没有找到使用自定义键盘的地方.电报在iPhone和桌面上运行,都是最新的.
示例代码:
$url = "https://api.telegram.org/bot<token>/sendMessage";
$keyb = array('ReplyKeyboardMarkup' => array('keyboard' => array(array("A", "B"))));
$content = array('chat_id' => <chat_id>, 'reply_markup' => $keyb, 'text' => "Test");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($content));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //fix http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
var_dump($server_output);
Run Code Online (Sandbox Code Playgroud) telegram-bot ×10
telegram ×4
php ×3
html ×2
api ×1
contacts ×1
dictionary ×1
elixir ×1
hyperlink ×1
python ×1
sendmessage ×1
ssl ×1
struct ×1
web-scraping ×1
webhooks ×1