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

I am trying to use Slack with Deno to send a message containing a select input. When any user modifies

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744245638a4564913.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信