最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

deno - Slack infinitely reusable interactive select input in message - Stack Overflow

programmeradmin6浏览0评论

I am trying to use Slack with Deno to send a message containing a select input. When any user modifies the select input value, the new value should be reflected for all users. This interaction should be able to occur infinite times, with any required logic also being hooked into this update event if needed.

So far, I have got it working once per message, but I cannot figure out how to get it to work for subsequent select value changes.

I've defined this function:

export const SelectTestFunctionDefinition = DefineFunction({
  callback_id: "select_test",
  title: "SelectTest",
  description: "select test",
  source_file: "functions/select_test/mod.ts",
  input_parameters: {
    properties: {
      interactivity: {
        type: Schema.slack.types.interactivity,
      },
    },
    required: ["interactivity"],
  },
  output_parameters: {
    properties: {
      message_ts: {
        type: Schema.slack.types.message_ts,
      }
    },
    required: [],
  },
});

with

export default SlackFunction(
  SelectTestFunctionDefinition,
  async ({ client }) => {
    const resp = await client.chat.postMessage({
      channel: CHANNEL,
      blocks: [stateSelectBlock()],
    })
    if (!resp.ok) {
      return {
        error: resp.error,
        outputs: {},
      }
    }
    return {
      outputs: {
        message_ts: resp.message.ts,
      },
      completed: false,
    };
  }
).addBlockActionsHandler([STATE_ID], stateActionHandler);

and

export const stateActionHandler: BlockActionHandler<typeof SelectTestFunctionDefinition.definition> = async ({ inputs, body, action, client }) => {
  await client.chat.update({
    channel: body.channel!.id,
    ts: body.message!.ts,
    blocks: [stateSelectBlock(action.selected_option.value, action.selected_option.text.text)],
  })

  await client.functionspleteSuccess({
    function_execution_id: body.function_data.execution_id,
    outputs: {},
  });
};

plus

export default function stateSelectBlock(initialStatus: Status = Status.0, initialStatusText: StatusText = StatusText.0) {
  return {
    "type": "input",
    "element": {
      "type": "static_select",
      "initial_option": {
        "text": {
          "type": "plain_text",
          "text": initialStatusText
        },
        "value": initialStatus
      },
      "options": [
        {
          "text": {
            "type": "plain_text",
            "text": StatusText.0
          },
          "value": Status.0
        },
        {
          "text": {
            "type": "plain_text",
            "text": StatusText.1
          },
          "value": Status.1
        },
        {
          "text": {
            "type": "plain_text",
            "text": StatusText.2
          },
          "value": Status.2
        },
        {
          "text": {
            "type": "plain_text",
            "text": StatusText.3
          },
          "value": Status.3
        }
      ],
      "action_id": STATE_ID,
    },
    "label": {
      "type": "plain_text",
      "text": "Status"
    }
  }
}

I suppose it makes some sense given that I am completing the function, but also I don't really know what else to do in order to keep it watching the input for changes.

发布评论

评论列表(0)

  1. 暂无评论