Skip to content

Instantly share code, notes, and snippets.

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
});
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);
});
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)
})
{
"servers": [
{
"url": "https://banana-drama.glitch.me"
}
],
"paths": {
"/drama": {
"post": {
"description": "Listen to when the user wants to add bananas to their text",
"servers": [
{
"url": "https://banana-drama.glitch.me"
}
],
"paths": {
"/joke": {
"get": {
"description": "Gets a joke for the user.",
"operationId": "Joke generator",
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
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);
}
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"})
}
})
SendBirdCall.addListener('LISTENER_ID', {
onInvitationReceived: (invitation) => {
invitation.accept();
try {
invitation.room.enter();
// The user has entered the room.
} catch (e) {
// error happened.
}
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`);
});