[英]send messages in google hangouts with node.js
I have looked for a long time trying to find a package that allows sending and reading messages in node.js 我已经寻找了很长时间,试图找到一个允许在node.js中发送和读取消息的包
I have found lots of guides on how to make bots in the G-Suite version of Hangouts, but I'm not a G-suite user and am looking to do it in the regular version. 我在环聊的G-Suite版本中找到了许多有关如何制作机器人的指南,但我不是G-suite用户,并且希望在常规版本中使用它。
I am aware of the Jaxbot hangouts-bot: https://github.com/jaxbot/hangouts-bot but this doesn't support sending and reading to group chats, and I'm looking for something that can. 我知道Jaxbot hangouts-bot: https : //github.com/jaxbot/hangouts-bot,但这不支持发送和阅读群聊,我正在寻找可以的东西。
I'm hoping the package can read/send messages in DMs and group chats, so leave an answer if you know of anything that can do it! 我希望该程序包可以在DM和群聊中读取/发送消息,因此,如果您知道有什么可以做的,请留下答案!
Thanks, privrax 谢谢,privrax
I've used the HangupsJS
package on npm to interact with Hangouts. 我在npm上使用了
HangupsJS
包与环聊进行交互。 https://npmjs.com/package/hangupsjs . https://npmjs.com/package/hangupsjs 。 Before installing, you will need to install the
coffeescript
package globally to install this package. 在安装之前,您需要全局安装
coffeescript
软件包才能安装此软件包。 Just use: npm install coffeescript -g
. 只需使用:
npm install coffeescript -g
。 If installing on a Mac use the sudo
prefix. 如果在Mac上安装,请使用
sudo
前缀。
This is what my bot looked like: 这是我的机器人的样子:
const Hangups = require('hangupsjs');
global.client = new Hangups();
const credsfunc = async function() {
return {
auth: async function() {
return process.env.TOKEN
}
}
}
client.on('chat_message', msg => {
console.log(msg)
if (msg.chat_message.message_content.segment[0].text == 'Hello') {
client.sendchatmessage(msg.conversation_id.id, [[0, 'Hi!']]);
}
});
client.connect(credsfunc).then(() => {
console.log('Client logged in.');
});
To get the authorization token you will need to follow these instructions: https://github.com/tdryer/hangups/issues/260#issuecomment-246578670 and replace process.env.TOKEN
with your OAuth token. 要获取授权令牌,您需要按照以下说明进行操作: https : //github.com/tdryer/hangups/issues/260#issuecomment-246578670并将
process.env.TOKEN
替换为OAuth令牌。
From here on, start your bot with node and then add them to a group chat. 从这里开始,使用node启动您的机器人,然后将其添加到群聊中。 They should start to read and respond to messages.
他们应该开始阅读并响应消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.