Created
July 12, 2020 22:38
-
-
Save jetaggart/8d4b354d0d9e8efe361b7f98bcc723a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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