Skip to content

Instantly share code, notes, and snippets.

@jetaggart
Created July 12, 2020 22:38
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 jetaggart/8d4b354d0d9e8efe361b7f98bcc723a1 to your computer and use it in GitHub Desktop.
Save jetaggart/8d4b354d0d9e8efe361b7f98bcc723a1 to your computer and use it in GitHub Desktop.
// backend/routes/index.js:6
router.post('/registrations', async (req, res, next) => {
try {
await axios.post(
'https://api.getbase.com/v2/leads',
{
data: {
'first_name': `${req.body.firstName}`,
'last_name': `${req.body.lastName}`,
'description': 'Lead created through Chat Inquiry',
'email': `${req.body.email}`
}
},
{
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.ZENDESK_CRM_TOKEN}`
}
}
);
const client = new streamChat.StreamChat(
process.env.STREAM_API_KEY,
process.env.STREAM_API_SECRET
);
const user = {
id: `${req.body.firstName}-${req.body.lastName}`.toLowerCase(),
role: 'user',
image: `https://robohash.org/${req.body.email}`
};
await client.upsertUsers([user, { id: 'sales-admin', role: 'admin' }]);
const channel = client.channel('messaging', user.id, {
members: [user.id, 'sales-admin'],
});
const token = client.createToken(user.id);
res.status(200).json({
userId: user.id,
token,
channelId: channel.id,
apiKey: process.env.STREAM_API_KEY
});
} catch (error) {
console.log(error, data.errors);
res.status(500).json({
error: error.message
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment