通过谷歌云功能打开一个松弛对话框

时间:2019-05-25 17:34:06

标签: javascript typescript google-cloud-functions slack-api

我正在使用此Slack Client与Slack api进行交互。当用户使用以下命令/openForm时,我试图在松弛状态下打开一个对话框。我还使用 google cloud功能来处理此功能。

这里是我的代码:

exports.openForm = (req, res) => {
  return Promise.resolve()
    .then(response => {
      return req.body;
    })
    .then(response => {
      const slack = new slackModel();
      const dialogObj = {
        trigger_id: response.trigger_id,
        dialog: {
          callback_id: "ryde-46e2b0",
          title: "Request a Ride",
          submit_label: "Request",
          notify_on_cancel: true,
          state: "Limo",
          elements: [
            {
              type: "text",
              label: "Pickup Location",
              name: "loc_origin"
            },
            {
              type: "text",
              label: "Dropoff Location",
              name: "loc_destination"
            }
          ]
        }
      };

      return slack.openForm(dialogObj);
    })
    .then(data => Promise.resolve(data));
}; 

这里是我的Slack模型类:

import { WebClient } from "@slack/web-api";

export class SlackModel {
  web: WebClient;
  constructor(message: string) {
    this.web = new WebClient(SLACK_TOKEN_HERE);
  }

  openForm(dialogObj): any {
    return this.web.dialog.open(dialogObj);
}

我在做什么错了,对话框无法打开,我收到一个错误:无法处理请求错误。

我检查了我的令牌,它是正确的。无法解决这个问题。

1 个答案:

答案 0 :(得分:0)

这段代码看起来有些错误:

exports.openForm = (req, res) => {
  return Promise.resolve()
    .then(response => {
      return req.body;
    })
    .then(response => {
      const slack = new slackModel();

如果我们专门研究:

.then(response => {
  return req.body;
})

这之后是另一个.then(),这意味着您返回的内容(req.body)本身就是一个诺言...但据我所知,事实并非如此。它要么是字符串,要么是传递给函数的缓冲区。