import { slackRequest } from './request.ts'
type AuthTestResponse = {
ok: boolean
user_id?: string
bot_id?: string
team_id?: string
[key: string]: unknown
}
/** Verify that Slack is authenticated with a user token rather than a bot token. */
export default async function smokeTest() {
const result = await slackRequest<AuthTestResponse>('auth.test')
const userIdentity = typeof result.user_id === 'string'
const botIdentity = typeof result.bot_id === 'string'
if (!userIdentity || botIdentity) {
throw new Error('The slack integration must use a Slack user token, not a bot token.')
}
return {
ok: true,
userIdentity,
botIdentity,
teamIdentity: typeof result.team_id === 'string',
}
}