- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个关于我目前正在使用的 Telegram 机器人的问题。我收到以下格式的用户消息:
update { update_id: 82618016,
message:
{ message_id: 363,
from: { id: 22303518, first_name: 'Steve', language_code: 'de-DE' },
chat: { id: 22303518, first_name: 'Steve', type: 'private' },
date: 1501501753,
text: 'j' } }
当我想访问聊天的 id 时,我可以毫无问题地使用
$.message.chat.id
一旦想要获取 message_id 或 first_name,我只会得到“undefined”。
$.message.chat.first_name
$.message.message_id
有人可以帮我吗?据我所知,我正确理解了消息的结构,所以我真的不知道这里有什么问题。
非常感谢您
编辑:我在这里添加了更多我的代码:
机器人的主要代码(包括 webhook)是这样的:
initializeBot();
function initializeBot(){
const Telegram = require('telegram-node-bot');
const PingController = require('./controllers/ping');
const OtherwiseController = require('./controllers/otherwise');
const tg = new Telegram.Telegram('MY_TOKEN_IS_HERE', {
webhook: {
url: 'https://xxx.herokuapp.com',
port: process.env.PORT || 443,
host: '0.0.0.0'
}
})
tg.router.when(new Telegram.TextCommand('/ping', 'pingCommand'), new PingController())
.otherwise (new OtherwiseController());
}
当调用 OtherwiseController 时,将调用以下代码(我将其简化为要点以阐明问题。
class OtherwiseController extends Telegram.TelegramBaseController {
handle($){
console.log($.message.chat.first_name);
console.log($.message.text);
console.log($.message.chat.id);
console.log($.message.message_id);
}
}
此消息的控制台输出
update { update_id: 82618020,
message:
{ message_id: 371,
from: { id: 22303518, first_name: 'Steve', language_code: 'de-DE' },
chat: { id: 22303518, first_name: 'Steve', type: 'private' },
date: 1501509762,
text: 'hello' } }
会是:
undefined
hello
22303518
undefined
最佳答案
使用下面的方法提取你的json对象的键,然后你可以用一个合适的键访问:
Object.keys($.message.chat);
关于javascript - 从 Telegram 消息中获取 message_id - node.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45415535/
我在网上看到有一些程序可以使用 Telegram CLI。 我想在他们之间做出选择 对于 Telegram bot API,有更多文档解释其功能,但对于 CLI,解释其特性的文档不多 似乎唯一了解的方
当我从按钮获得触发器时,我正在尝试使用 Telethon 发送 Telegram 消息。 当由 NewMessage 事件等事件触发时,我的 Telethon 方法工作正常,但是如何使用其他触发器(即
API 对象 User有房产language_code - Telegram 如何确定用户的语言,以及如何更改它? 我希望根据 language_code 为用户创建响应语言,但我不确定我是否可以信任
我有很多 Telegram channel ,他们以 24\7 的格式发送消息 “购买 usdjpy sl 145.2 tp 167.4” “eurusd 卖出 sl 145.2 tp 167.4”
我对Telegram机器人有疑问。 我需要键盘和嵌入式键盘,是否可以同时启用这两个功能? 最佳答案 根据Telegram documentation,当前不可能同时为reply_markup传递两个或
有人知道 Telegram 如何制作丰富的预览吗?了解它对我正在进行的开发非常有用。它是服务器端的特性,所以我认为代码不可用。不是吗? 最佳答案 它使用 Open Graph protocol :ht
Telegram是一种基于云的聊天服务。他们所有的客户端都是开源的。我想知道是否有办法在我自己的服务器上托管“私有(private)” Telegram 服务。 如果没有,是否有任何东西可以提供 te
为了发送常规消息,我使用 - const uri = `https://api.telegram.org/bot${token}/sendMessage?chat_id=${channelId}&
我正在尝试创建一个机器人,它可以读取/接收特定 channel 中的所有消息并将它们发送给我。我的问题是我找不到在我的机器人中访问这些消息的方法 重要的是: 我不是该 channel 的管理员或创建者
任何人都可以告诉我如何从我的 Telegram Bot 获取有关用户的信息。想象一下我的机器人是我 channel 中的管理员用户,我想获取我的 channel 用户列表或在新用户加入时引起注意。我怎
举个例子,我知道这个帐户存在“https://t.me/everexio ”,但当我单击查看时,它失败,并显示“没有包含您提供的用户名的 Telegram 帐户。”我在不同的群体中多次看到过这个问题。
我知道有一些特殊的网站,例如 Youtube、Vimeo 和...,我可以将我的视频上传到其中一个网站,并将其链接放在 Telegram 的消息中,在下面显示其大视频预览消息并通过其 InApp-Pl
我有一个机器人可以创建包含用户提供的一些 URL 的消息。Telegram 为这些 url 创建链接预览。预览已缓存。 有时 url 的内容发生变化,那么 Telegram 提供的预览就过时了。所以我
telegram 提供了一种衡量 channel 消息浏览量的方法。我很好奇是否有一种方法可以衡量特定群体每月的每月活跃用户或总独立浏览量。 最佳答案 简短回答:是。 您可以使用许多在线工具或机器人分
我如何在 Telegram 机器人上创建一个三划线菜单,类似于他们对 Jobs 机器人所做的那样?它应该与此类似: 我们如何称呼这种菜单? 最佳答案 您可以使用机器人父亲命令添加将显示在菜单上的命令。
网站telegram如何给登录用户发送消息? Telegram Login for Websites Telegram bots are a powerful communication tool,
我想连接一个简单的 Telegram Bot 来读取来自群组(我不是管理员)的消息。我已经将机器人添加到组中,但它不起作用。 这是我在 Python 中的代码: import telepot from
我想使用它的 deep linking 通过 Telegram 设置身份验证接口(interface)。 为了进行身份验证,在我的应用中,我要求用户点击如下链接: https://telegram.m
Telegram 中是否有任何事件 API 机器人 或 核心检测谁查看了用户或 channel 或群组或机器人配置文件? 一些机器人和应用程序声称他们可以做到这一点,但我没有在 Telegram AP
我正在尝试通过电报bot中的SendVoice方法发送语音消息,但是它将语音作为文档文件发送(而不是播放)。 ffmpeg将ogg文件转换为opus编码。 https://api.telegram.o
我是一名优秀的程序员,十分优秀!