这是一些上下文,我正盯着使用 slack BOLD SDK for python,虽然指南很棒......为块套件部分发布那些巨大的代码块是一团糟,所以我想创建一个新的类/函数并导入它..所以,而不是这个:
main.py
-------
@app.message("hello")
def message_hello(message, say):
# say() sends a message to the channel where the event was triggered
say(
blocks=[
{
"type": "section",
"text": {"type": "mrkdwn", "text": f"Hey there <@{message['user']}>!"},
"accessory": {
"type": "button",
"text": {"type": "plain_text", "text": "Click Me"},
"action_id": "button_click"
}
}
],
text=f"Hey there <@{message['user']}>!"
)
我可以做这个:
msg.py:
--------
def hello():
return blocks=[
{
"type": "section",
"text": {"type": "mrkdwn", "text": f"Hey there <@{message['user']}>!"},
"accessory": {
"type": "button",
"text": {"type": "plain_text", "text": "Click Me"},
"action_id": "button_click"
}
}
],
text=f"Hey there <@{message['user']}>!"
main.py
--------
import from lib msg
@app.message("hello")
def message_hello(message, say):
# say() sends a message to the channel where the event was triggered
say(msg.hello())
自从我上次使用 Python 以来已经有一段时间了,我在返回部分遇到了问题msg.py
。
任何人都可以刷新我的记忆并帮助我吗?
谢谢!