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/server.js:20 | |
async function getPreviousTranscript(leadId) { | |
const headers = { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json', | |
'Authorization': `Bearer ${process.env.ZENDESK_CRM_TOKEN}` | |
} | |
const response = await axios.get( | |
`https://api.getbase.com/v2/leads/${leadId}`, | |
{ headers: headers } |
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/server.js:33 | |
app.post('/messages', async (req, res) => { | |
try { | |
const leadId = req.body.leadId; | |
let previousTranscript = await getPreviousTranscript(leadId); | |
const payload = { | |
'description': `${previousTranscript}\n${req.body.author}: ${req.body.message.text}` | |
} | |
const headers = { | |
'Accept': 'application/json', |
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
// frontend/src/SalesChat.js:7 | |
function SalesChat({ username, leadId, chatClient, channel }) { | |
async function handleMessage(_channelId, message) { | |
await axios.post("http://localhost:8080/messages", { message, author: username, leadId: leadId }); | |
return channel.sendMessage(message); | |
} | |
return ( | |
<Chat client={chatClient} theme="commerce light"> | |
<Channel channel={channel} doSendMessageRequest={handleMessage}> |
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/server.js:15 | |
const streamClient = new StreamChat( | |
process.env.STREAM_API_KEY, | |
process.env.STREAM_API_SECRET | |
); | |
// ... | |
// backend/server.js:57 | |
app.post("/stream-chat-credentials", async (req, res) => { |
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
const startChat = async () => { | |
const response = await axios.post("http://localhost:8080/stream-chat-credentials", { | |
username, leadId | |
}); | |
const token = response.data.token; | |
const channelId = response.data.channelId; | |
const chatClient = new StreamChat(response.data.apiKey); | |
await chatClient.setUser({ id: response.data.userId, name: response.data.userName }, token); | |
const channel = chatClient.channel("messaging", channelId); |
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
// frontend/src/App.js:5 | |
function App() { | |
const [username, setUsername] = useState(''); | |
const [leadId, setLeadId] = useState(''); | |
const [channel, setChannel] = useState(null); | |
const [chatClient, setChatClient] = useState(null); | |
const startChat = async () => { | |
// ... | |
} |
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
// frontend/src/App.js:45 | |
if (chatClient && channel) { | |
return ( | |
<div className="App"> | |
<Chat client={chatClient} theme={'messaging light'}> | |
<Channel channel={channel}> | |
<Window> | |
<ChannelHeader /> | |
<MessageList /> | |
<MessageInput /> |
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
// frontend/src/App.js:15 | |
async function register() { | |
const response = await fetch("http://localhost:8080/registrations", { | |
method: "POST", | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ | |
firstName, |
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', |
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
// frontend/src/App.js:7 | |
function App() { | |
const [firstName, setFirstName] = useState(''); | |
const [lastName, setLastName] = useState(''); | |
const [email, setEmail] = useState(''); | |
// We'll get to these in a bit | |
const [chatClient, setChatClient] = useState(null); | |
const [channel, setChannel] = useState(null); |
NewerOlder