import { WebClient } from '@slack/web-api';
import * as wmill from 'windmill-client@1';
type Slack = {
token: string;
};
export async function main(
response_url: string,
text: string,
channel_id?: string,
command?: string
) {
if (command === "@mention") {
// @mention - use Slack API
const slack = await wmill.getResource<Slack>('f/slack_bot/bot_token');
const web = new WebClient(slack.token);
await web.chat.postMessage({
channel: channel_id,
text: `Echo: ${text}`
});
} else {
// Slash command - use response_url
await fetch(response_url, {
method: 'POST',
body: JSON.stringify({ text: `Echo: ${text}` })
});
}
}Submitted by hugo989 4 days ago