Our team procrastinated on writing bug reports. So we built an AI to do it for us
Suhana Jabin
Posted on August 18, 2024
1. Case Study : AI for creating Bug Reports
Team Problem:
Keeping track of multiple messages in a team can be quite difficult. Discord, a popular platform for team discussions, can soon become overwhelmed with lengthy conversations, making it difficult to find important messages and at times, you can even forget those discussed points .
Team Solution:
What if there was a way to automatically summarize these messages and convert them into actionable insights?
In this article, we will explore a basic approach to do that—using Python to scrape Discord messages, harnessing the summarization power of Google Gemini (a powerful tool that uses Machine learning models for text generation) , and effortlessly integrating these summaries into GitLab as issues. This process not only saves time but also ensures that your team's most important discussions are efficiently tracked and managed.
How it works
Our approach:
- Fetching the discord message chunks from the server.
- Summarizing it with the help of Gemini
- Creating an issue in the Gitlab repo that contains the summary of selected discord issue.
Let's take a quick look on how to implement this idea:
The whole task is divided into 3 basic sections:
Watch Discord
We are utilizing Discord APIs to helps us gather messages from a Discord channel, so we can later process and summarize them using tools like Gemini. This way, we can quickly organize and make sense of large amounts of information.
We need to create a Bot to get the messages from Discord Channel .
So , let's start by creating a Bot in a new application.
a) Creating a new application
- Login to Discord
Navigate to the application page
Click on the "New Application" Button on the top right corner.
b) Setting up your Bot
Navigate to the Bot tab in application page
Provide the username and note the Bot Access Token as we need it in the future for connecting this Bot to the respective discord channel.
If in case you can't see the Bot Access Token , click the Reset Token to generate a new Bot Access Token.
If you want others to invite your Bot to any servers, make sure the public bot is ticked.
Make sure message content intent is ticked to enable your bot to receive messages.
Great! So now you have successfully set up your Bot account.
c) Inviting your Bot into your server
Head to the Oauth2 tab and navigate to the OAuth2 URL Generator section.
Click the Bot checkbox and Bot permission section will appear.
Upon clicking the bot checkbox, there will be another box for providing Bot permissions. Choose the permissions as per your usecase. Be careful when you provide the administrator permission to the bot.
You can see a link will appear in the generated URL section.
Open that url in a new tab and you'll be prompted to select the server.
After you select the server, click authorize and you're done with the Bot creation part!
d) The Coding part!
We need to create a Python script to scrap the discord messages in the specific channel.
i) Make sure you have the right permissions
- We need the channel ID for scraping and it can only be obtained when you're granted administrator privilege.
ii) Install the required libraries
pip install discord
iii) Provide the Bot Access Token
bot_token = **os.getenv('DISCORD_BOT_TOKEN')
- Bot Access Token is necessary to run the client.
iv) Giving the right permission to the client
intents = discord.Intents.default()
- Discord Intents are a way of telling which events your bot wants to receive.
- This line creates an Intent object with default settings and by default, the bot will receive a minimal set of events- messages,reactions and basic events.
v) Enabling the message intent
intents.messages = True
- This line allows the bot to receive events related to messages.
vi) Configuring Bot Client
client = discord.Client(intents=intents)
- This line configures the bot client with the right event permissions.
vii) Defining an event handler in Python
async def on_ready():
print(f'Logged in as {client.user}')
guild = discord.utils.get(client.guilds) # Get the first guild (server) the bot is in
if guild:
print(f'Connected to guild: {guild.name}')
for channel in guild.channels:
print(f'Channel: {channel.name} (ID: {channel.id})')
else:
print('No guilds found.')
channel = client.get_channel(channel_id)
if channel:
async for message in channel.history(limit=100):
print(f'{message.author}: {message.content}')
else:
print('Channel not found.')
- Firstly, the client retrieves the first guild/server it is connected to.
- Secondly, it checks for the channel with the given channel ID among the list of channels, and if it matches, the client starts an asynchronous loop to fetch the last 100 messages.
To read the rest of the article, visit : https://journal.hexmos.com/bug-description-generator/
Posted on August 18, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024