问题
I need my slack bot to support user input date and time, I know there is DatePicker which I can input a certain date. But I also need time, I am thinking to use a text field to just input string, but it's annoying that users have to deal with format stuff every time. Is there a better way to do this? or is it possible to make a date time picker by myself?
edit: Users might input any specific time, any hour or minute.
回答1:
The Slack API currently only provides a date picker, not not a datetime picker.
However, you can create a datetime picker yourself: Combine a date picker element with a static select menu element that has all the time options and voila you have a datetime picker.
This would be easiest to be implemented in a Modal, since this allows a user to set values for multiple elements at the same time.
Here is an example with block-kit. Depending on the granularity of your time values you may want to generate the list of options programmatically.
And if you need to provide a more granular input, like down to the minute, then I would suggest to place two selects:
- First for the hour (00 - 23)
- Second for the minute (00 - 59)
Here is an updated block-kit example on how this would look.
And here is a screenshot of the example:
Dito for seconds if you need them.
The maximum allowed number of options for a select element is 100, so this will work.
来源:https://stackoverflow.com/questions/58618607/is-it-possible-to-create-a-slack-datetime-picker-element