Rom*_*ser 6 bots bolts-framework slack-api slack
我正在构建一个 slack FAQ 应用程序,它使用消息反应来收集问题的最佳答案。我的计划是通过使用reaction_added事件获取 TS 属性,然后使用conversations.history获取消息内容的方法来保存任何具有积极反应的 Slack 消息。
这适用于父级或非线程消息,但它不适用于线程内的回复消息。出于某种原因,该conversations.history方法在使用线程回复的 TS 时会返回一条不相关的消息。
我检查了 Slack APIconversations.history方法文档,看看回复是否以任何特殊方式处理。我查看了conversations.replies方法以查看它是否有帮助,但由于reaction_addedevent 只是为消息提供了一个 TS id,而没有可以与该conversations.replies方法一起使用的 thread_ts 值。
我正在使用螺栓框架。这是尝试使用reaction_added事件 withconversations.history方法获取消息内容的代码片段:
app.event('reaction_added', async ({ event, context, say }) => {
try {
const result = await app.client.conversations.history({
token: process.env.SLACK_USER_TOKEN,
channel: event.item.channel,
latest: event.item.ts,
limit: 1,
inclusive: true
});
save(`${result.messages[0].text}`);
}
catch (error) {
console.error(error);
}
});
Run Code Online (Sandbox Code Playgroud)
预期结果:发布反应的线程回复的消息内容
实际结果:slack channel中最新消息的消息内容
我不确定它最近是否发生了变化,或者我误读了文档,但conversations.repliesAPI 端点不需要thread_ts包含父线程时间戳的值来检索线程回复。
event.item.ts事件提供的值足以reaction_added检索添加了反应的回复的消息内容。
因此,要获取添加了反应的消息的消息内容,您可以将我原来的问题中的代码更新为:
app.event('reaction_added', async ({ event, context, say }) => {
try {
const result = await app.client.conversations.replies({
token: process.env.SLACK_USER_TOKEN,
channel: event.item.channel,
ts: event.item.ts
});
save(`${result.messages[0].text}`);
}
catch (error) {
console.error(error);
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
931 次 |
| 最近记录: |