← Public packages
@kody/slack
Read Slack conversations and safely send messages as the authorizing user through the saved slack OAuth integration.
src/smoke-test.ts
38 lines · 1.1 KB · TypeScriptimport { byoConnectUrl, resolveIntegrationName, slackRequest } from './request.ts'
import { inputRecord } from './validation.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(params: Record<string, unknown> = {}) {
const input = inputRecord(params)
const integration = resolveIntegrationName(input.integration)
const result = await slackRequest<AuthTestResponse>('auth.test', {}, integration)
const userIdentity = typeof result.user_id === 'string'
const botIdentity = typeof result.bot_id === 'string'
if (!userIdentity || botIdentity) {
throw new Error(
'The ' +
integration +
' integration must use a Slack user token (xoxp), not a bot token (xoxb). ' +
'Connect a Slack app with User Token Scopes at ' +
byoConnectUrl(integration) +
'. See the package README.',
)
}
return {
ok: true,
integration,
userIdentity,
botIdentity,
teamIdentity: typeof result.team_id === 'string',
}
}