Create a Jira Cloud issue from Microsoft Teams


Get Started

Not the template you're looking for? Browse more.

About the template


This template demonstrates how to create an issue in Jira Cloud with the data sent by a Microsoft Teams command. After the issue has been created, newly created issue key is posted back to Microsoft Teams channel. Get started to learn more.

About ScriptRunner Connect


What is ScriptRunner Connect?

ScriptRunner Connect is an AI assisted code-first (JavaScript/TypeScript) integration platform (iPaaS) for building complex integrations and automations.

Can I try it out for free?

Yes. ScriptRunner Connect comes with a forever free tier.

Can I customize the integration logic?

Absolutely. The main value proposition of ScriptRunner Connect is that you'll get full access to the code that is powering the integration, which means you can make any changes to the the integration logic yourself.

Can I change the integration to communicate with additional apps?

Yes. Since ScriptRunner Connect specializes in enabling complex integrations, you can easily change the integration logic to connect to as many additional apps as you need, no limitations.

What if I don't feel comfortable making changes to the code?

First you can try out our AI assistant which can help you understand what the code does, and also help you make changes to the code. Alternatively you can hire our professionals to make the changes you need or build new integrations from scratch.

Do I have to host it myself?

No. ScriptRunner Connect is a fully managed SaaS (Software-as-a-Service) product.

What about security?

ScriptRunner Connect is ISO 27001 and SOC 2 certified. Learn more about our security.

Template Content


README

Scripts

TypeScriptOnMSTeamsCommandEvent
Teams Command Event via an Outgoing Webhook

README


๐Ÿ“‹ Overview

This template demonstrates how to create an issue in Jira Cloud with the data sent by a Microsoft Teams command. After the issue has been created, newly created issue key is posted back to Microsoft Teams channel.

๐Ÿ–Š๏ธ Setup

  1. Create connectors: Configure the API connection and event listener by creating connectors for Jira Cloud and Microsoft Graph. Or you can use existing ones.
  2. Configure parameters: Set the necessary parameters to match your requirements.
  3. Check permissions:
    • If using a self-managed Microsoft Graph Connector, ensure the app has the required API permissions:
      • User.ReadBasic.All
      • ChatMessage.Send
      • Chat.ReadWrite
    • An administrator must approve these permissions.
    • After updating permissions, reauthorize your Microsoft Graph Connector.

๐Ÿš€ Using the template

Trigger a Microsoft Teams command using @command_name <ISSUE_SUMMARY>. Once the event is processed, a new issue will be created in Jira Cloud, and the issue key will be sent back to Microsoft Teams.

API Connections


TypeScriptOnMSTeamsCommandEvent

import Microsoft from './api/microsoft';
import JiraCloud from './api/jira/cloud';
import { MicrosoftTeamsOutgoingWebhookEvent } from '@sr-connect/microsoft/events';

/**
 * This function creates a Jira Cloud issue based on data triggered by Teams command, 
 * and then posts back a message to Teams containing newly created issue key.
 * 
 * Command syntax: @command_name <ISSUE_SUMMARY>
 * 
 * @param event Object that holds Teams Command Event via an Outgoing Webhook event data
 * @param context Object that holds function invocation context data
 */

export default async function (event: MicrosoftTeamsOutgoingWebhookEvent, context: Context): Promise<void> {
    if (context.triggerType === 'MANUAL') {
        console.error('This script is designed to be triggered externally or manually from the Event Listener. Please consider using Event Listener Test Event Payload if you need to trigger this script manually.');
        return;
    }

    const { ISSUE_TYPE_NAME, JIRA_PROJECT_KEY } = getEnvVars(context);

    try {
        // Extract summary from Teams command event
        const text = event.text;

        // Remove the command name from the text and remove extra whitespace
        const summary = text.substring(text.indexOf('</at>') + 5).replace(/&nbsp;/g, ' ').trim();

        // Check if the summary is specified
        if (!summary) {
            // If not, post approriate message back to Teams chat where the command originated from
            await Microsoft.Teams.Messaging.Chat.sendMessage({
                chat_id: event.conversation.id ?? '',
                body: {
                    body: {
                        content: 'Issue summary is required',
                        contentType: 'text'
                    },
                }
            });

            // And halt the operation
            return;
        }

        // Find the project to use based on pre-defined project key
        const project = await JiraCloud.Project.getProject({
            projectIdOrKey: JIRA_PROJECT_KEY
        });

        // Find all the issue types for given project
        const issueTypes = await JiraCloud.Issue.Type.getTypesForProject({
            projectId: +(project.id ?? 0) // + sign converts the string to number
        });

        // // Find the issue type to use based on pre-defined issue type name
        const issueType = issueTypes.find(it => it.name === ISSUE_TYPE_NAME);
        // Check if the issue type was found
        if (!issueType) {
            // If not, then throw an error
            throw Error('Issue type not found');
        }

        // Log out the information that the issue is about to be created
        console.log('Creating Issue', {
            projectId: project.id,
            issueTypeId: issueType.id,
            summary
        });

        // Create the issue
        const issue = await JiraCloud.Issue.createIssue({
            body: {
                fields: {
                    project: {
                        id: project.id ?? '0'
                    },
                    issuetype: {
                        id: issueType.id ?? '0'
                    },
                    summary
                }
            }
        });

        // Log out created issue key
        console.log(`Issue created: ${issue.key}`);

        // And post a messages with newly created issue key back to Teams chat where the command originated from
        await Microsoft.Teams.Messaging.Chat.sendMessage({
            chat_id: event.conversation.id ?? '',
            body: {
                body: {
                    content: `Issue Created: ${issue.key}`,
                    contentType: 'text'
                }
            }
        });
    } catch (e) {
        // If something goes wrong, log out the error
        console.error('Error while processing command', e);

        // And post appropriate message back to where the command originated from
        await Microsoft.Teams.Messaging.Chat.sendMessage({
            chat_id: event.conversation.id ?? '',
            body: {
                body: {
                    content: 'Something went wrong while creating issue',
                    contentType: 'text'
                },
            }
        });
    }
}

interface EnvVars {
    JIRA_PROJECT_KEY: string;
    ISSUE_TYPE_NAME: string;
}

export function getEnvVars(context: Context) {
    return context.environment.vars as EnvVars;
}
Documentation ยท Support ยท Suggestions & feature requests