首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Slackbot无法接收消息

Slackbot无法接收消息
EN

Stack Overflow用户
提问于 2020-12-01 17:05:30
回答 1查看 116关注 0票数 0

我正在尝试创建一个简单的slackbot,我可以让它在start和几乎任何其他东西上运行,但是它不会接收来自任何频道的传入消息。它不会产生任何错误

到目前为止我尝试过的事情:

将bot添加到channel

  • console日志记录中的
  1. 在消息块
  2. 中添加一个catch

不管我做什么,机器人似乎完全忽略了提示"on.message“。我还是不明白。我的密码在下面。

代码语言:javascript
复制
require("dotenv").config();
const { WebClient } = require("@slack/web-api");
const { createEventAdapter } = require("@slack/events-api");
const slackEvents = createEventAdapter(process.env.SLACK_SIGNING_SECRET);
const { RTMClient } = require("@slack/rtm-api");
const axios = require('axios')
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const express = require("express");
const bodyParser = require("body-parser");
const pool = require("./pool");
const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("build"));

let config = {
  headers: {
    "X-Auth-Client": process.env.BG_AUTH_CLIENT,
    "X-Auth-Token": process.env.BG_AUTH_TOKEN,
  },
};
  const PORT = process.env.PORT || 5000;
  app.listen(PORT, () => {
    console.log("server running on: ", PORT);
  });
const token = process.env.SLACK_TOKEN;

const web = new WebClient(token);

const conversationId = "C0139RJPUEM";

// The client is initialized and then started to get an active connection to the platform
const rtm = new RTMClient(token);



slackEvents.on('error', console.error);

slackEvents.start().then(() => {
    (async () => {
      const res = await web.chat.postMessage({
        icon_emoji: ":email:",
        channel: conversationId,
        text: "Testing connection",
      });

    message
      console.log("Message sent: ", res.ts);
    })();
    console.log("bot listening on port", PORT);
});

    slackEvents.on("message", (event) => {
      console.log(
        `Received a message event: user ${event.user} in channel ${event.channel} says ${event.text}`
      );
      (async () => {
        // See: https://api.slack.com/methods/chat.postMessage
        const res = await web.chat.postMessage({
          icon_emoji: ":email:",
          channel: conversationId,
          text: "Testing message",
        });

        // `res` contains information about the posted message
        console.log("Message sent: ", res.ts);
      })();
      // }
    });
EN

回答 1

Stack Overflow用户

发布于 2020-12-01 20:53:35

我想我明白了,我使用的是一个不兼容的库,而且我没有设置API事件订阅和其他一些愚蠢的东西。哦,好吧。希望这能帮助那些偶然遇到这件事的人。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65095090

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档