Mit*_*unS 12 node.js slack-api slack
这是我第一次尝试创建一个松弛的bot,我将这个模板代码添加到单词上,我没有做任何更改,只是在出现故障时重新混合,正确地复制粘贴了auth令牌,一切正常。直到我将#general频道限制为Full Member
用户为止。
这是我在故障日志中看到的错误。
PostMessage Error: restricted_action
这是代码:
const postAnnouncementToChannel = (user, announcement) => {
const { title, details, channel } = announcement;
let announcementData = {
token: process.env.SLACK_ACCESS_TOKEN,
channel: channel,
text: `:loudspeaker: Announcement from: <@${user}>`,
attachments: JSON.stringify([
{
title: title,
text: details,
footer: 'DM me to make announcements.'
}
])
};
send(announcementData, user);
}
const send = async(data) => {
data.as_user = true; // send DM as a bot, not Slackbot
const result = await axios.post(`${apiUrl}/chat.postMessage`, qs.stringify(data))
try {
if(result.data.error) console.log(`PostMessage Error: ${result.data.error}`);
} catch(err) {
console.log(err);
}
}
Run Code Online (Sandbox Code Playgroud)
通过测试
https://api.slack.com/methods/chat.postMessage/test 使用bot-token说
{
"ok": false,
"error": "restricted_action"
}
Run Code Online (Sandbox Code Playgroud)
使用xoxp-token进行测试可以得到:
{
"ok": false,
"error": "missing_scope",
"needed": "chat:write:user",
"provided": "identify,bot"
}
Run Code Online (Sandbox Code Playgroud)
不。您没有丢失任何范围。只是您用来认证您的应用的用户无法发布到常规频道中。显然,管理员限制了可以在该频道中发布消息的人员,例如,仅限管理员。
请使用对该频道具有发布权的用户来验证您的应用,或切换到其他频道进行测试。
机器人不是正式会员,所以我必须使用用户令牌
xoxp-token
Run Code Online (Sandbox Code Playgroud)
发布到 chat.postmessage,使用
as_user:false
Run Code Online (Sandbox Code Playgroud)
并且必须添加一个missing_scope,即
chat:write:user
Run Code Online (Sandbox Code Playgroud)
然后我就能正确地完成这项工作。感谢 @girliemac 在这方面提供的帮助。
https://github.com/slackapi/template-announcement-approvals/issues/6
谢谢
归档时间: |
|
查看次数: |
279 次 |
最近记录: |