Rank 1: Thread
Hi, I'm loving Appwrite and how easy it is to get started.
I'm using a function that I've added a document create event to listen for. The event string looks like this databases.slack-events.collections.events.documents.*.create. I am however not seeing any executions for the function.
Here is the function
import { StatusCodes, getReasonPhrase } from 'http-status-codes'import { WebClient } from '@slack/web-api'import { Client, Databases } from 'node-appwrite'
export default async ({ req, res, log, error }: any) => { log(req.bodyRaw) // Raw request body, contains request data log(JSON.stringify(req.body)) // Object from parsed JSON request body, otherwise string log(JSON.stringify(req.headers)) // String key-value pairs of all request headers, keys are lowercase log(req.scheme) // Value of the x-forwarded-proto header, usually http or https log(req.method) // Request method, such as GET, POST, PUT, DELETE, PATCH, etc. log(req.url) // Full URL, for example: http://awesome.appwrite.io:8000/v1/hooks?limit=12&offset=50 log(req.host) // Hostname from the host header, such as awesome.appwrite.io log(req.port) // Port from the host header, for example 8000 log(req.path) // Path part of URL, for example /v1/hooks log(req.queryString) // Raw query params string. For example "limit=12&offset=50" log(JSON.stringify(req.query)) // Parsed query params. For example, req.query.limit
const document = req.body as SlackEventDocument
let err = null as string | null switch (document.event_type) { case 'app_mention': err = await handleAppMention(document) break default: error('Unhandled event type: ' + document.event_type) return res.send(getReasonPhrase(StatusCodes.OK), StatusCodes.OK) }
if (err !== null) { error('Failed to handle event') error(err) return res.send( getReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR), StatusCodes.INTERNAL_SERVER_ERROR ) }
log('Successfully handled event')
return res.send(getReasonPhrase(StatusCodes.OK), StatusCodes.OK)}
const slackClient = new WebClient(Bun.env['SLACK_OAUTH'])
const appwriteClient = new Client()appwriteClient .setEndpoint(Bun.env['APPWRITE_ENDPOINT']) .setProject(Bun.env['APPWRITE_PROJECT'])const db = new Databases(appwriteClient)
async function handleAppMention( document: SlackEventDocument): Promise<string | null> { //! test response to slack try { await slackClient.chat.postMessage({ channel: document.event_channel_id, text: 'Hi there! you said: \n> ' + document.event_text, }) } catch (err) { return err }
// Delete the processed document try { await db.deleteDocument('slack-events', 'events', document.$id) } catch (err) { return err }
return null}Here is the appwrite.json for that function
{ "$id": "654ee4144ec39d66688a", "name": "Process Slack Event", "runtime": "bun-1.0", "execute": ["any"], "events": [ "databases.slack-events.collections.events.documents.*.create" ], "schedule": "", "timeout": 15, "enabled": true, "logging": true, "entrypoint": "src/process-slack-event.ts", "commands": "bun install", "ignore": ["node_modules", ".npm"], "path": "./"}