JIRA JQL Generator Slack Bot

By
 
import os
import re
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
from abilities import llm_prompt
from jira import JIRA

# Install the Slack app and get xoxb- token in advance
app = App(token=os.environ["SLACK_BOT_TOKEN"])

# Dictionary to store the generated JQL and the user who requested it
jql_dict = {}

# List of reserved JQL words
reserved_words = ["and", "or", "not", "empty", "null", "contains", "issue", "project", "text", "word", "in", "is", "was", "during"]

@app.command("/hello-socket-mode")
def hello_command(ack, body):
    user_id = body["user_id"]
    ack(f"Hi, <@{user_id}>!")

@app.event("app_mention")
def event_test(body, say, event):

About this template

This app, named "Slack Mention Jira Query Generator", is designed to assist you in generating Jira Query Language (JQL) queries directly from Slack. When you mention the app in a Slack message, it will generate a JQL based on your message and ask if you want to run the query. If you agree, it will execute the query on Jira and return the results in the same Slack thread. The app is designed to handle multiple users at the same time and ensures that the correct JQL is associated with the user who requested it. It also formats the JQL results to share the links of the issues instead of the actual issue object, making it easier for you to navigate to the issues directly from Slack. To use this app, you will need to provide the following environment variables: - SLACK_BOT_TOKEN: You can get this by creating a new app in your Slack workspace, adding the bot scope, and installing the app in the workspace. - SLACK_APP_TOKEN: This can be generated by enabling Socket Mode for the app in the Slack API settings and generating an App-Level token. - JIRA_API_TOKEN and JIRA_EMAIL: These can be generated from your Jira account settings. - JIRA_SERVER_URL: This is the URL of your Jira server.

Introduction to the JIRA JQL Generator Slack Bot Template

Welcome to the step-by-step guide on how to set up and use the JIRA JQL Generator Slack Bot template on the Lazy platform. This template is designed to help you generate Jira Query Language (JQL) queries directly from Slack. When you mention the app in a Slack message, it will create a JQL based on your message and ask if you want to run the query. If you agree, it will execute the query on Jira and return the results in the same Slack thread.

To get started with this template, simply click on "Start with this Template" on the Lazy platform.

Setting Environment Secrets

Before you can use the JIRA JQL Generator Slack Bot, you need to set up a few environment secrets. These are necessary for the app to communicate with Slack and Jira. Here's what you need to do:

  • SLACK_BOT_TOKEN: This token allows your app to work with Slack. You can obtain it by creating a new app in your Slack workspace, adding the bot scope, and installing the app in the workspace.
  • SLACK_APP_TOKEN: This token is used for Socket Mode in Slack. You can generate it by enabling Socket Mode for your app in the Slack API settings and creating an App-Level token.
  • JIRA_API_TOKEN and JIRA_EMAIL: These credentials are used to authenticate with Jira. You can generate them from your Jira account settings.
  • JIRA_SERVER_URL: This is the URL of your Jira server where the queries will be run.

Enter these details in the Environment Secrets tab within the Lazy Builder interface.

External Integrations

Before using the template, you need to set up integrations with Slack and Jira:

  • Create a new app in your Slack workspace and install it.
  • Enable Socket Mode for your Slack app and generate the necessary tokens.
  • Generate an API token from your Jira account and note down your Jira email.

These steps are crucial for the app to function correctly and to ensure that it can communicate with both Slack and Jira.

Using the Test Button

Once you have set up the environment secrets, you can use the Test button to deploy the app. The Lazy CLI will prompt you for any required user input after you use the Test button. If the app requires additional input, provide it through the Lazy CLI as prompted.

If the app uses an API, Lazy will provide you with a dedicated server link to use the API. In the case of FastAPI, you will also receive a docs link to interact with the app.

How to Use the Interface

After deploying the app using the Test button, you can interact with the Slack bot directly within your Slack workspace. Mention the bot in a message to generate a JQL query. The bot will respond in the thread, asking if you want to run the generated query. If you choose to run it, the bot will execute the query on Jira and return the results in the Slack thread.

Here's a sample interaction with the bot:

User: @JiraBot Find all open bugs in the project ABC
Bot: Generating a JQL, please wait...
Bot: Generated JQL: `project = 'ABC' AND issuetype = 'Bug' AND status = 'Open'`. Do you want to run this query? [View JQL](JiraLink)

Clicking "Yes" will run the query and the bot will post the results in the thread. Clicking "No" will cancel the operation.

By following these steps, you can easily set up and use the JIRA JQL Generator Slack Bot on the Lazy platform to streamline your workflow and enhance your productivity within Slack.

Category
Technology
Last published
April 7, 2024

More templates like this

AI Query Generator Slack Bot for BigQuery

This app allows users to interact with a Slack bot, ask a question about the data in a table or request the table schema, and then uses the latest ChatGPT to generate a query that is executed on BigQuery to return the results. The app includes a retry mechanism for query generation in case of an error (up to two retries) and provides the LLM with the table info to generate more accurate queries. The table schema is only printed if it is successfully retrieved. All errors from retries are now passed to the LLM. The generated query is printed before the results, and the results are displayed in a pretty table format. The bot uses the Slack API to send and receive messages and parses the user's message to determine the action to take. The bot always responds in a thread to the original message.

Python
Slack
OpenAI

Basic Slack Bot

This is a simple starting point for a Slack bot it just responds hi to a mention.

Slack

Create Slack Channel using API

An app for Slack integration allowing the creation of public channels using the Slack API. This webhook app requires 'SLACK_BOT_TOKEN' to authenticate with slack api. It also requires channels:manage scope enabled to create channels. Further enchancements to prompts may allow the app to add the user to the channel.

Slack
Home
/
JIRA JQL Generator Slack Bot