Lookup user id by email in slack bot - jira

Use case
I have JIRA where users can create issues/cards. Whenever a user creates the card, I would like to mention the creator in the slack channel.
I created a slack bot and webhook URL. Added the webhook URL in JIRA and it's sending the message.
Message that will be sent from JIRA
Hi, <#issue> ,
Please look into this issue `{{issue.summary}}`
{{issue.url.customer}}.
Reporter - {{issue.reporter.emailAddress}}
JIRA can give me only the reporter email address, but to mention the user in slack i need the user id of slack.
Is there any way we can achieve the same?

There is this API : users.lookupByEmail
you can use this to fetch userId, but given that you are using just Webhook URL, you'll need to implement additional code.

Related

Change email address in replyto or replyall

We are using Microsoft Graph API to send and receive emails. Just like outlook, during a reply is composed, we want to change, remove or add new recipients. However, MS graph api of replyall or reply does not allow changing any email address.
How can we achieve this functionality using MS Graph API ?
You should use create-reply endpoint https://learn.microsoft.com/en-us/graph/api/message-createreply?view=graph-rest-1.0&tabs=http
That will create a draft reply message (and return the Id for that) that you can then patch any way you want including updating the recipient addresses and replyto then you send that draft message.

Sending an MS Teams message using the Microsoft Graph API or BOT API

I'm trying to implement the following solution: a web application that subscribes to all MS teams chat messages. If a message contains forbidden text, the application should somehow warn the user (Ideally by replying to the same message, or, if not possible, initiate a conversation with the user).
I'm able to receive all chat webhooks and process them, but I could not find any way to post a message back to the Teams channel using the Graph API (the operation described in https://learn.microsoft.com/en-us/graph/api/channel-post-messagereply?view=graph-rest-beta&tabs=http
is not supported for Application permissions - only delegated ones which isn't suitable for our case).
So I'm trying to send proactive messages using the Bot framework, However, the bot framework requires a teams conversation ID which I don't have (the graph API webhook provides the team, channel and user IDs, none of which are accepted by the Bot API).
Does anyone know of a way I can retrieve the teams conversation ID using the team ID and channel ID provided by the graph API?
Thanks,
Dan
ConversationId for channel messages are combination of channelId and messageId both can be found in payload you get webhook notification. You can reply to existing conversation by using following by building converstionId like this:
conversationId = $"{channelId};messageid={messageId}"
For reply to work, your Bot needs to installed in the team and should have serviceURL saved at some place to refer back. Here is sample code which show how you can reply to existing message.
var serviceURL = "YOUR Service URL- You get this in each bot payload";
MicrosoftAppCredentials.TrustServiceUrl(serviceURL, DateTime.MaxValue);
using var connector = new ConnectorClient(new Uri(serviceURL, MicrosoftAppId, MicrosoftAppPassword);
var conversationId = $"{channelId};messageid={messageId}";
var replyActivity = MessageFactory.Text($"This is simple reply to existing conversation.");
replyActivity.Conversation = new ConversationAccount(id: conversationId);
var response = await connector.Conversations.SendToConversationAsync(conversationId, replyActivity);
For 1:1 reply- please take a look at Sending Proactive Message documentation.

MSGraph - Getting external email conversation from reply

My team is building a ticketing system. The goal is when we receive a new email we create a new ticket. All responses to that email are saved on the same ticket.
We have these basic goals working in simple cases, however, there is one case that we are struggling to find a good solution for. A client will email us, which creates a ticket, and we reply back requiring information. The client will send our reply to someone internal to their company. Then they will send the response back to us by replying with "see below". This response will have the conversation between them and their co-worker in the comment section of the email. The comment section will also contain our entire email chain which we don't want to duplicate.
The issue we are having is grabbing the conversation they had from the comment section to include with their response of "see below" and add them to the ticket. The only method we have come up with to solve this is manually parsing the comment section of the email, however, this is error-prone.
Does anyone know of a better way of tracking conversations they send you through the email?
We are using msgraph internally to send and receive emails and using their apis they have uniqueBody and body, but they don't seem to have a way to break the body up into its different parts.
What I need any of these options
1- get list of unique bodies from the email chain without using conversation Id as it will not be sufficient in some cases.
2- get the previous conversation Id of the incoming email. I mean if that email is a list of emails and it forwards to me.
UUID uuid = UUID.randomUUID();
message.addProperty("InternetMessageId", String.format("%s",uuid.toString()));
send InternetMessageId with a unique identifier to grab conversation id
change order only

How to link slack user with github account?

I am creating a slack bot and want to be able to link the slack user with the github account.
Is there a way I can link the 2 either via slack or github API's?
I was thinking if of storing users slack username and github username in a JSON object, i.e.:
{
"slack_username": "JoeBlogs",
"github_username": "JoeBlogs123"
}
In order to do this, I would need to retrieve the users' username from slack API when the user authorises the app / bot.
I was thinking if I add a redirect_url to my slack app then it would redirect user to http://example.com/redirect if the users data is sent along to this redirect url, I would be able save it in a database of sorts.
If I then did the same with the github API then I could reference database in order to find slack users JoeBlogs github account and vice versa.
Is it possible to use the redirect_url like this? I couldn't see any user data being sent to but maybe it is nested somewhere I couldn't see it?
Is there a better way to link the 2 accounts?
Assuming you are using Install button to install your Slack app into the workspace, this is a payload which will be sent to your response_url:
{
"access_token": "xoxp-XXXXXXXX-XXXXXXXX-XXXXX",
"scope": "incoming-webhook,commands,bot",
"team_name": "Team Installing Your Hook",
"team_id": "XXXXXXXXXX",
"incoming_webhook": {
"url": "https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX",
"channel": "#channel-it-will-post-to",
"configuration_url": "https://teamname.slack.com/services/BXXXXX"
},
"bot":{
"bot_user_id":"UTTTTTTTTTTR",
"bot_access_token":"xoxb-XXXXXXXXXXXX-TTTTTTTTTTTTTT"
}
}
See for details.
Then, using access_token in combination with users.identity API method you will get basic information about Slack user (playing with the scopes you requested during the install process you can get different fields of Slack user identity).

#channel Slack notification in Jenkins post-build action

I am integrating a Slack bot in Jenkins post-build action. I have been able to send notification and create custom messages using the Slack plugin, however I wanted to send a #channel or #bot in the bot message which can be used to urgently notify the team.
Is there any existing way/hack to do this? Unfortunately, using these keywords via the plugin just result in them being rendered as plain text, without any broadcast action.
To mention someone or a channel you can use one of the following syntax:
<!channel>
<!group>
<!here>
<!everyone>
<#USERID>
<#CHANNELID>
See Basic message formatting for more information.

Resources