diff --git a/package.json b/package.json index 79238c5..ad1c684 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "thirdweb-support-discord-bot", - "version": "2.0.11", + "version": "2.0.12", "description": "A self-hosted dedicated forum-based support Discord bot for the thirdweb community.", "main": "src/bot.ts", "author": "Waren Gonzaga", diff --git a/src/bot.js b/src/bot.js index c1abd87..e27a1d8 100644 --- a/src/bot.js +++ b/src/bot.js @@ -30,10 +30,10 @@ const { version } = require("../package.json"); require("dotenv").config(); // discord bot tokens -const { - DISCORD_BOT_TOKEN, - DISCORD_SUPPORT_ROLE_ID, - CONTEXT_ID, +const { + DISCORD_BOT_TOKEN, + DISCORD_SUPPORT_ROLE_ID, + CONTEXT_ID, ASKAI_CHANNEL } = process.env; const token = DISCORD_BOT_TOKEN; @@ -107,7 +107,7 @@ client.on("messageCreate", async (message) => { }, onError: async (error) => { console.error(error); - + // send a message indicates unseccesful response from the AI await message.channel.messages.fetch(aiMessageLoading.id).then((msg) => msg.edit({ @@ -575,7 +575,9 @@ client.on("messageCreate", async (message) => { if (mentioned.roles.cache.hasAny(...roleIDs) && !member.roles.cache.hasAny(...roleIDs)) { message.reply({ embeds: [sendEmbedMessage(`We have moved to a community driven discord support model.\n\nYou can ask me all things thirdweb in the <#${ASKAI_CHANNEL}> channel. Use the command \`!askai\` or \`!ask\` followed by your question to get started.`)], - }); + }).then(msg => { + setTimeout(() => msg.delete(), 60000) + }) } } @@ -642,10 +644,10 @@ client.on("threadCreate", async (post) => { ); // send message upon creating of new ticket - post.send({ - embeds: [sendEmbedMessage(config.reminder_newpost)], - components: [CloseButtonComponent()], - }); + // post.send({ + // embeds: [sendEmbedMessage(config.reminder_newpost)], + // components: [CloseButtonComponent()], + // }); // log any new posts console.log( @@ -662,7 +664,7 @@ client.on("threadCreate", async (post) => { botId: CONTEXT_ID, query: question, onComplete: async (query) => { - + await post.messages.fetch(aiMessageLoading.id).then((msg) => msg.edit({ content: "", @@ -672,7 +674,7 @@ client.on("threadCreate", async (post) => { components: [FeedbackButtonComponent()], }) ); - + }, onError: (error) => { console.error(error); @@ -692,8 +694,20 @@ client.on("interactionCreate", async (interaction) => { const closeTag = post.availableTags.filter((item) => { return item.name == config.tag_name_close; }); + const resolutionTag = post.availableTags.filter((item) => { + return item.name == config.tag_name_resolve; + }); + const escalateTag = post.availableTags.filter((item) => { + return item.name == config.tag_name_escalate; + }); let initialTags = [closeTag[0].id, ...postTags]; let tags = [...new Set(initialTags)]; + let initialTagsResolution = [resolutionTag[0].id, ...postTags].filter( + (item) => { + return item != escalateTag[0].id; + } + ); + let tagsResolution = [...new Set(initialTagsResolution)]; const question = post.name; if (interaction.channel.ownerId != interaction.user.id) return; if (interaction.customId === "close") { @@ -733,6 +747,28 @@ client.on("interactionCreate", async (interaction) => { ephemeral: true, }); await interaction.message.edit({ components: [] }); + + // send embed message upon executing the resolve command + await interaction.channel.send({ + embeds: [sendEmbedMessage(`${config.reminder_resolve}`)], + content: `🔔 <@${interaction.channel.ownerId}>`, + }); + + // then archive / close it + await interaction.channel.edit({ + appliedTags: tagsResolution, + archived: false, + }); + sendData( + { + post_id: interaction.channel.id, + resolution_time: statusTime, + resolved_by: "Thirdweb Assistant", + }, + config.datasheet_resolve + ); + + } else if (interaction.customId === "not-helpful") { sendData( { @@ -742,11 +778,13 @@ client.on("interactionCreate", async (interaction) => { config.datasheet_feedback ); await interaction.reply({ - embeds: [sendEmbedMessage(`Thank you so much for your feedback!`)], + embeds: [sendEmbedMessage(`Thank you for your valuable feedback, this will help us improve the responses of our AI assistant.\n\nIn the meantime, would you like to contact a human customer success agent? Just click the link or the button below to submit a ticket.`)], content: `🔔 <@${interaction.channel.ownerId}>`, ephemeral: true, + components: [CloseButtonComponent()], }); await interaction.message.edit({ components: [] }); + } } }); diff --git a/src/utils/core.js b/src/utils/core.js index f65a85c..5833199 100644 --- a/src/utils/core.js +++ b/src/utils/core.js @@ -24,13 +24,7 @@ const sendEmbedMessage = (message) => { * @param {string} message * @returns pre-defined embed style */ -const CloseButtonComponent = () => { - const close = new ButtonBuilder() - .setCustomId('close') - .setLabel('Close') - .setEmoji('⚒️') - .setStyle(ButtonStyle.Danger); - +const CloseButtonComponent = () => { const support = new ButtonBuilder() .setLabel('Submit a Ticket') .setEmoji('💬') @@ -38,7 +32,7 @@ const CloseButtonComponent = () => { .setStyle(ButtonStyle.Link); const row = new ActionRowBuilder() - .addComponents(close, support); + .addComponents(support); return row }