slackのchannnel idを名前に変換する
slackのメッセージにはchannelのidが入っているが、名前にはなっていない.
名前に変換するにはchannels.info
を使う必要がありそう.
以下はtypescriptを利用したサンプル.
ライブラリには
slack-node-sdkを利用
import { WebClient, WebAPICallResult, RTMClient } from '@slack/client'; const web = new WebClient(token); const rtm = new RTMClient(token); interface ChannelInfoResponse extends WebAPICallResult { channel: { id: string; name: string; // rest fields are omitted }; } interface EventMessage { subtype?: string; type: string; channel: string; user: string; text: string; ts: string; } rtm.on('message', async (message: EventMessage) => { const channelId = message.channel; const info = (await web.channels.info({ channel: channelId, })) as ChannelInfoResponse; const name = info.channel.name; console.log(`channel name is ${name}`); });