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 passMessageToSendbirdBot = async (payload) => { | |
try { | |
const response = await axios.post(`https://api-${process.env.SENDBIRD_APP_ID}.sendbird.com/v3/bots/YOUR_BOT_ID/ai_chatbot_replies`, { | |
messages: [ | |
{ role: 'user', content: payload.text } | |
] | |
}, { | |
headers: { 'Api-Token': process.env.SENDBIRD_API_TOKEN, 'Content-Type': 'application/json' }, | |
maxBodyLength: Infinity | |
}); |
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
app.post('/message_to_bot', authenticateIncomingSlackCalls, async (req, res) => { | |
const { text } = req.body; | |
res.json({ response_type: 'in_channel', text: `🤖\nQ: ${text}` }); | |
passMessageToSendbirdBot(req.body); | |
}); |
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
app.post("/drama", async (req, res) => { | |
let dramaText = "" | |
try { | |
dramaText = insertRandomBanana(req.query.text) || insertRandomBanana(req.body.text) | |
} catch (e) { | |
console.log(e) | |
} | |
res.status(200).send(dramaText) | |
}) |
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
{ | |
"servers": [ | |
{ | |
"url": "https://banana-drama.glitch.me" | |
} | |
], | |
"paths": { | |
"/drama": { | |
"post": { | |
"description": "Listen to when the user wants to add bananas to their text", |
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
"servers": [ | |
{ | |
"url": "https://banana-drama.glitch.me" | |
} | |
], | |
"paths": { | |
"/joke": { | |
"get": { | |
"description": "Gets a joke for the user.", | |
"operationId": "Joke generator", |
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
async function updateTicketStatus (channelUrl) { | |
try { | |
const ticket = await axios.get(`https://desk-api-${APP_ID}.sendbird.com/platform/v1/tickets?channel_url=${channelUrl}`, { | |
headers: { | |
"Content-Type": "application/json; charset=utf8", | |
"SENDBIRDDESKAPITOKEN": SENDBIRDDESKAPITOKEN | |
} | |
}) | |
const ticketId = ticket.data.results[0].id |
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
app.post("/hand_off", async(req, res) => { | |
const channelUrl = req.body.channel_url; | |
try { | |
const updateResponse = await updateTicketStatus(channelUrl); | |
if (updateResponse.success) { | |
res.status(200).send({ "message": "Handing over to a human. Just a minute please." }); | |
} else { | |
throw new Error(updateResponse.message); | |
} |
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
app.post("/hand_off", async(req, res) => { | |
console.log(req.body) | |
const channelUrl = req.body.channel_url | |
try { | |
res.status(200).send({"message":"handing over to a human. Just a minute please."}) | |
} catch (e){ | |
res.status(400).send({"error":true, "message":"Failed to perform hand over"}) | |
} | |
}) |
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
SendBirdCall.addListener('LISTENER_ID', { | |
onInvitationReceived: (invitation) => { | |
invitation.accept(); | |
try { | |
invitation.room.enter(); | |
// The user has entered the room. | |
} catch (e) { | |
// error happened. | |
} |
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
room.on('invitationAccepted', (invitation) => { | |
// Invitation was accepted by `invitation.invitee` | |
}); | |
room.on('invitationDeclined', (invitation) => { | |
// Invitation was declined by `invitation.invitee` | |
console.log(`invitation is declined`); | |
}); |
NewerOlder