Skip to content

Instantly share code, notes, and snippets.

@isaidspaghetti
Created July 17, 2020 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaidspaghetti/1eebf1a62534d5970a2c6b5ffaeb2c82 to your computer and use it in GitHub Desktop.
Save isaidspaghetti/1eebf1a62534d5970a2c6b5ffaeb2c82 to your computer and use it in GitHub Desktop.
backend router handler
//backend/routes/index.js:46
router.post('/registrations', async (req, res, next) => {
try {
await createHubspotContact(firstName, lastName)
const client = new StreamChat.StreamChat(apiKey, apiSecret);
[customer, supporter] = createUsers(firstName, lastName)
await client.upsertUsers([
customer,
supporter
]);
const channel = client.channel('messaging', customer.id, {
members: [customer.id, supporter.id],
});
const customerToken = client.createToken(customer.id);
res.status(200).json({
customerId: customer.id,
customerToken,
channelId: channel.id,
apiKey,
});
} catch (err) {
console.error(err);
res.status(500).json({ error: err.message });
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment