harmony/test/slash-http.ts

28 lines
753 B
TypeScript
Raw Normal View History

2021-04-08 09:40:50 +00:00
import { SlashClient } from '../mod.ts'
2021-03-14 09:42:05 +00:00
import { SLASH_ID, SLASH_PUB_KEY, SLASH_TOKEN } from './config.ts'
import { listenAndServe } from 'https://deno.land/std@0.90.0/http/server.ts'
const slash = new SlashClient({
id: SLASH_ID,
token: SLASH_TOKEN,
publicKey: SLASH_PUB_KEY
})
await slash.commands.bulkEdit([
{
name: 'ping',
description: 'Just ping!'
}
])
const options = { port: 8000 }
console.log('Listen on port: ' + options.port.toString())
listenAndServe(options, async (req) => {
2021-03-14 10:16:44 +00:00
const d = await slash.verifyServerRequest(req)
if (d === false) return req.respond({ status: 401, body: 'not authorized' })
2021-03-14 09:42:05 +00:00
2021-03-14 10:16:44 +00:00
console.log(d)
if (d.type === 1) return d.respond({ type: 1 })
d.reply('Pong!')
2021-03-14 09:42:05 +00:00
})