Slack API chat_deleteScheduledMessage调用返回invalid_scheduled_message_id问题
Slack定时消息删除失败
invalid_scheduled_message_id问题解决 问题根源
你在构造SCHEDULED_MESSAGES时,将post_at参数强制转换为了字符串类型,Slack的chat_scheduleMessage接口要求post_at必须为整数类型的Unix时间戳。传字符串的情况下,接口虽然会临时返回一个格式正确的ID,但后端实际上没有创建合法的定时消息任务,因此调用删除接口时会提示ID无效。
解决方案
- 修正
post_at的参数类型,去掉多余的字符串转换:
# 修改前的代码 # 'post_at': str(int((datetime.now() + timedelta(seconds=20)).timestamp())) # 修改后的代码 SCHEDULED_MESSAGES = [ {'text': 'First message', 'post_at': int((datetime.now() + timedelta(seconds=20)).timestamp()), 'channel': 'C02BT07KS8N'}, {'text': 'Second Message!', 'post_at': int((datetime.now() + timedelta(seconds=30)).timestamp()), 'channel': 'C02BT07KS8N'} ]
- 确认你的Slack应用令牌拥有
chat:write、chat:write:public(公开频道场景)/chat:write:private(私有频道场景)权限,且机器人已经加入你操作的目标频道。 - 可选验证步骤:创建定时消息后调用
list_scheduled_messages方法,打印实际存在的定时消息ID,和你从创建接口拿到的ID做对比,确认任务创建成功。
内容的提问来源于stack exchange,提问作者Ryota Akai
相关产品推荐
相关产品推荐

