标签: telegram-bot

如何在本地机器上测试telegram bot webhook?

我正在开发一个Telegram机器人,我想使用Webhooks而不是轮询来从Telegram服务器获取消息.
我正在开发和测试localhost上的应用程序,该应用程序不是可访问的Web主机,因此我无法将其设置为Webhook URL.

现在我想知道如何通过Webhooks在本地机器上从Telegram获得真正的消息?

php webhooks telegram-bot

27
推荐指数
1
解决办法
8264
查看次数

如何使用Telegram Bot API发送表情符号?

我需要用我的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发送表情符号?

php telegram-bot

26
推荐指数
5
解决办法
5万
查看次数

Elixir将struct转换为map

我正在尝试将结构转换为地图,以便能够清除所有的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中没有匹配的函数子句

struct dictionary elixir telegram-bot

26
推荐指数
3
解决办法
1万
查看次数

使用html在电报机器人上发送粗体和斜体文本

我用电报创建了一个机器人

我想将带有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*输出应该是粗体但它不起作用

html sendmessage telegram telegram-bot

26
推荐指数
4
解决办法
7万
查看次数

Telegram Bot如何从频道或组中删除或删除消息或媒体

我想知道删除邮件或文件的示例,如照片

我没有找到这方面的任何功能性教程,

telegram telegram-bot

23
推荐指数
2
解决办法
6万
查看次数

Webhook与Telegram Bot API有问题

为什么我的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)

api ssl telegram-bot

21
推荐指数
3
解决办法
3万
查看次数

如何在电报机器人中显示选项?

我想写一个bot电报.如何在我的bot中添加可能的选项.我插入一个具有此功能的示例bot的图片.

在此输入图像描述

telegram-bot

20
推荐指数
2
解决办法
2万
查看次数

如何创建链接以通过 Telegram 联系特定电话号码?

所以我发现我可以在 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?

先感谢您

html hyperlink contacts telegram telegram-bot

20
推荐指数
3
解决办法
2万
查看次数

Telegram机器人可以读取频道的消息

电报机器人可以读取/访问我或机器人既不是管理员的电报频道吗?

我知道直到去年11月才有可能,但我听说有些人已经这样做了,但到目前为止我无法做到.

我非常感谢您的投入和知识.

Ps任何解决方法都会很棒.

python web-scraping telegram telegram-bot

19
推荐指数
1
解决办法
2万
查看次数

PHP中的Telegram Bot自定义键盘

我正在尝试使用自定义键盘在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)

php telegram-bot

18
推荐指数
2
解决办法
3万
查看次数