Skip to content

Instantly share code, notes, and snippets.

@shodgetts
Created April 20, 2021 21:39
Embed
What would you like to do?
WebHook Handler
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const axios = require("axios");
const app = express();
const port = process.env.PORT || 5000;
const base64 = require("js-base64").Base64;
const fetch = require("node-fetch");
//chat client
const StreamChat = require("stream-chat").StreamChat;
const chatClient = StreamChat.getInstance(app_key, app_secret);
//middleware
app.use(cors());
app.post("/", (req, res) => {
let body = "";
req.on("data", (chunk) => {
body += chunk;
});
// got payload from Stream
req.on("end", async () => {
let parsedBody = JSON.parse(body);
if (parsedBody.type === "channel.updated") {
// logic here
console.log(parsedBody);
}
res.status(200).send("OK");
});
});
app.listen(port, () => {
console.log(`server running on port ${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment