Slack Bot に URL を貼り付けさせると (edited) になってうざい件
事象
Slack API (App) に chat.postMessage
で URL を投げつけると OGP とかが展開されたあと (edited)
がついてBot 自身がメッセージを更新しているわけでもないのに気持ちが悪い.
対策
結論: text= で送らずに block を使う
今までは text= で送っていたが,
url = 'https://slack.com/'
client.chat_postMessage(
channel=channel_id,
text=url,
)
block で送るようにしたところ (edited)
が付かなくなった!
url = 'https://slack.com/' blocks = [ { 'type': 'section', 'text': { 'type': 'mrkdwn', # plain_text ではなく mrkdwn にする必要がある 'text': url } }, ] client.chat_postMessage( channel=channel_id, blocks=blocks, text=url, )
ちなみに, blocks を渡す場合でも text を指定するのがよい. attachments の fallback と同様, この text はデスクトップ通知やプッシュ通知バナーの表示テキストとして使われる. text 無しで送り続けていると API のレスポンスで text を入れる様に下記警告が入る.
UserWarning: The top-level `text` argument is missing in the request payload for a chat.postMessage call - It's a best practice to always provide a `text` argument when posting a message. The `text` argument is used in places where content cannot be rendered such as: system push notifications, assistive technology such as screen readers, etc. warnings.warn(missing_text_message, UserWarning)