| name | slack-api-5-slash-commands |
| description | Sub-skill of slack-api: 5. Slash Commands. |
| version | 1.0.0 |
| category | business |
| type | reference |
| scripts_exempt | true |
5. Slash Commands
5. Slash Commands
from slack_bolt import App
from datetime import datetime, timedelta
import random
import os
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
@app.command()
():
ack()
channel = command[]
user = command[]
result = client.chat_postMessage(
channel=channel,
blocks=[
{
: ,
: {
: ,
: ,
:
}
},
{
: ,
: {
: ,
:
}
},
{
:
},
{
: ,
: [
{: , : }
]
}
],
text=
)
client.pins_add(channel=channel, timestamp=result[])
():
ack()
text = command.get(, )
re
parts = re.findall(, text)
(parts) < :
client.chat_postEphemeral(
channel=command[],
user=command[],
text=
)
question = parts[]
options = parts[:]
option_blocks = []
emojis = [, , , , , , , , ]
i, option (options[:]):
option_blocks.append({
: ,
: {
: ,
:
}
})
blocks = [
{
: ,
: {: , : , : }
},
{
: ,
: {: , : }
},
{: },
*option_blocks,
{: },
{
: ,
: [
{: , : }
]
}
]
result = client.chat_postMessage(
channel=command[],
blocks=blocks,
text=
)
i ((options[:])):
emoji_names = [, , , , , , , , ]
client.reactions_add(
channel=command[],
timestamp=result[],
name=emoji_names[i]
)
():
ack()
text = command.get(, ).strip()
parts = text.split(, )
(parts) < :
client.chat_postEphemeral(
channel=command[],
user=command[],
text=
)
time_str = parts[]
message = parts[]
time_map = {: , : , : }
unit = time_str[-]
unit time_map:
client.chat_postEphemeral(
channel=command[],
user=command[],
text=
)
:
amount = (time_str[:-])
seconds = amount * time_map[unit]
ValueError:
client.chat_postEphemeral(
channel=command[],
user=command[],
text=
)
post_at = (datetime.now().timestamp()) + seconds
client.chat_scheduleMessage(
channel=command[],
post_at=post_at,
text=
)
client.chat_postEphemeral(
channel=command[],
user=command[],
text=
)
():
*Content truncated — see parent skill full reference.*