Bot User Events API for Direct Messages - slack-api

I created a slack app with a Bot User that uses the Events API to listen to messages in channels the bot hangs out.
Oauth scope: bot,chat:write:bot
I subscribed to the following Bot Events:
message.channels
message.groups
message.im
message.mpim
When I invite my bot to join a channel, I receive a POST request as follows:
{
[...]
"event": {
"user": "U24BYHV19",
"inviter": "U03BN91GN",
"text": "<#U24BYHV19|my_bot> has joined the channel",
"type": "message",
"subtype": "channel_join",
"ts": "1472139425.000019",
"channel": "C24UWQE85",
"event_ts": "1472139425.000019"
},
"type": "event_callback",
[...]
}
When I send a message in a channel where the bot hangs out, I receive a POST request as follows:
{
[...]
"event": {
"type": "message",
"user": "U03BN91GN",
"text": "hello <#U24BYHV19>",
"ts": "1472139444.000021",
"channel": "C24UWQE85",
"event_ts": "1472139444.000021"
},
"type": "event_callback",
[...]
}
When I send a direct message to my bot, I receive a POST request as follows:
{
[...]
"event": {
"type": "message",
"user": "U03BN91GN",
"text": "hello pager",
"ts": "1472139450.000032",
"channel": "D24DC8UTG",
"event_ts": "1472139450.000032"
},
"type": "event_callback",
[...]
}
The problem is, how can I determine that someone is talking to my bot via direct message? :) Because I want to respond if someone talks to my bot.

Channels of Direct Messages start with an D instead of an C.

Related

How to find parent_message_id of reply message in graph api

I mean that Incoming reply mail is which mail reply,
To find this I want parent_message_id by using this I'm easily find parent_mail.
below code is respone of reply mail.
I want to find It's parent mail means below mail is which mail reply
To find parent mail I want parent_mail_id How can I find this ?
{
"#odata.etag": "W/\"CQAAABYAAABexZ50mSS0TKajvW/Uc3jZAAAhk64J\"",
"id": "AQMkADAwATM3ZmYAZS01OWRhLTM5MjgtMDACLTAw....",
"createdDateTime": "2023-02-02T08:39:59Z",
"lastModifiedDateTime": "2023-02-02T08:40:01Z",
"changeKey": "CQAAABYAAABexZ50mSS0TKajvW/Uc3jZAAAhk64J",
"categories": [],
"receivedDateTime": "2023-02-02T08:40:00Z",
"sentDateTime": "2023-02-02T08:39:46Z",
"hasAttachments": false,
"internetMessageId": "<CAJjLavQHv0SDMHxiKpRUCE=NU9X4AnL2QfPKjLJMbPeudvNP-A#mail.gmail.com>",
"subject": "Re: Meet for lunch 12:40?",
"bodyPreview": "12:40 reply mail\r\n\r\nOn Thu, 2 Feb 2023 at 13:06, ** <****#outlook.com> wrote:\r\nThe new cafeteria is open.",
"importance": "normal",
"parentFolderId": "AQMkADAwATM3ZmYAZS01OWRhLTM5MjgtMDACLTAwCgAuAAADNqdil3J7jU_HbfQfdBJYbQEAXsWedJkktEymo71v1HN42QAAAgEMAAAA",
"conversationId": "AQQkADAwATM3ZmYAZS01OWRhLTM5MjgtMDACLTAwCgAQAAo6snnrhhJOv0qLJ4Io1Fo=",
"conversationIndex": "AQHZNtkeCjqyeeuGEk6/SosngijUWq67VhwA",
"isDeliveryReceiptRequested": null,
"isReadReceiptRequested": false,
"isRead": false,
"isDraft": false,
"webLink": "https://outlook.live.com/owa/?ItemID=AQMkADAwATM3ZmYAZS01OWRhLTM5MjgtMDACLTAwCgBGAAADNqdil3J7jU%2BHbfQfdBJYbQcAXsWedJkktEymo71v1HN42QAAAgEMAAAAXsWedJkktEymo71v1HN42QAAACGV0fkAAAA%3D&exvsurl=1&viewmodel=ReadMessageItem",
"inferenceClassification": "focused",
"body": {
"contentType": "html",
"content": "<html><head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body><div dir=\"ltr\">12:40 reply mail </div><br><div class=\"gmail_quote\"><div dir=\"ltr\" class=\"gmail_attr\">On Thu, 2 Feb 2023 at 13:06, ** <***#outlook.com> wrote:<br></div><blockquote class=\"gmail_quote\" style=\"margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex\">The new cafeteria is open.</blockquote></div></body></html>"
},
"sender": {
"emailAddress": {
"name": "****",
"address": "***#gmail.com"
}
},
"from": {
"emailAddress": {
"name": "****",
"address": "****"
}
},
"toRecipients": [
{
"emailAddress": {
"name": "***",
"address": "****#outlook.com"
}
}
],
"ccRecipients": [],
"bccRecipients": [],
"replyTo": [],
"flag": {
"flagStatus": "notFlagged"
}
},
I've send mail by using /sendMail graph api and for this sent mail I've reply mail by using other platform(ex:gmail) ,So how can I know incoming message parent message I mean which message reply is it
You need to take the conversationId from your message and filter messages by conversationId
GET https://graph.microsoft.com/v1.0/me/messages?$filter=conversationId eq '{conversation_id}'
Then order the messages by conversation index. The property conversationIndex does not support filtering on the server, so you need to order messages on the client as a string.
From ordered messages you are able to get the parent message.
There Isn't Any way to find parent_id by using reply mail response , In response provide parent_folderId but It Isn't useful to find parent_id
There Is one way to find parent_id If parent and reply messages have same conversation-id but Isn't then It cannot be possible to find the correct parent message

Microsoft Graph API - send message in channel by using team tagging

This graph API send a message in the channel
POST https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/messages
{
"body": {
"content": "Hello world"
}
}
Also, following the docs from https://learn.microsoft.com/en-us/graph/api/resources/chatmessagemention?view=graph-rest-1.0 I can mention user, channel or team
But I am looking for how I can mention Tags while sending message in a channel.
After doing some research, came up with a solution thought of posting here for others:
Graph API
POST https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/messages
Body here is critical
{
"subject": "This is very urgent!",
"importance": "urgent",
"body": {
"contentType": "html",
"content": "Programatically mentioning of Tagged users <at id=\"0\">String_1234</at>"
},
"mentions": [
{
"id": 0,
"mentionText": "String_1234",
"mentioned": {
"tag": {
"#odata.type": "#microsoft.graph.teamworkTagIdentity",
"id": "", //tag id
"displayName": "" //tag name
}
}
}
]
}

Create new mail message with Microsoft Graph API

When using the MS Graph API to POST a Mail message, the message is created in DRAFT mode. Is there any way to create a new regular mail message which is not in DRAFT?
In addition, is there any option to POST a new message using MIME format in the body?
When you create the Message you need to set the MessageFlags extended property to make it appear as if it was a Sent Message. You generally also want to set the ClientSubmitTime https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtagclientsubmittime-canonical-property and the delivery time https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtagmessagedeliverytime-canonical-property which affect how the messages will sort in Outlook. For MIME its export only in Beta at the moment https://developer.microsoft.com/en-us/graph/blogs/mime-format-support-for-microsoft-graph-apis-preview/
{
"Subject": "test1234",
"Sender": {
"EmailAddress": {
"Name": "blah",
"Address": "blah#blah.com"
}
},
"Body": {
"ContentType": "HTML",
"Content": "123Body"
},
"SingleValueExtendedProperties": [
{
"PropertyId": "Integer 0x0E07",
"Value": "1"
},
{
"PropertyId": "SystemTime 0x0039",
"Value": "2019-06-12T10:10:47.2048+10:00"
},
{
"PropertyId": "SystemTime 0x0E06",
"Value": "2019-06-12T10:10:47.2048+10:00"
}
]
}

Are the organizer and isOrganizer Attributes in MS-Graph event working?

I'm trying to use the MS Graph API to create a new event with a technical user on behalf of a resource. The event is created, but the organizer and isOrganizer Attributes are not considered or ignored in the response.
I tried multiple requests as well as in 'v1.0' and 'beta' mode. In this SO question How to create event where current user not organizer using Microsoft Graph API it is stated that this is not implemented at the time of the original post (2016). But I didn't find anything in the Graph-API docs, saying that this would not work.
This is the request body:
{
"subject": "Instant Meeting: " + user_name,
"body": {
"contentType": "HTML",
"content": "Dieser Termin wurde vom Konferenzraum eingestellt"
},
"isOrganizer": "false",
"organizer" : {
"emailAddress": {
"address":user_email,
"name": user_name
}
},
"start": {
"dateTime": start,
"timeZone": "Europe/Berlin"
},
"end": {
"dateTime": end,
"timeZone": "Europe/Berlin"
},
"location":{
"displayName": room.get('name'),
"locationEmailAddress": room.get('email'),
"locationType" : "conferenceRoom"
},
"attendees": [
{
"emailAddress": {
"address":user_email,
"name": user_name
},
"type": "required"
},
{
"emailAddress": {
"address":room.get('email'),
"name": room.get('name')
},
"type": "resource"
}
]
}
The relevant parts of the response are:
response.get('organizer')
{'emailAddress': {'address': 'testraum-nichtbuche...t-mail.de', 'name': 'TestRaum - NICHT BUCHEN'}}
'emailAddress': {'address': 'testraum-nichtbuche...t-mail.de', 'name': 'TestRaum - NICHT BUCHEN'}
__len__: 1
response.get('isOrganizer')
True
If this worked properly, I would expect the 'organizer' to be user_email and the flag to be set to False.
Can anyone provide a working example for this?
Thanks!
This behavior has not changed. The organizer and isOrganizer properties cannot be defined by the caller, they are automatically assigned by Exchange:
setting event organizer with Outlook Calendar REST API
Outlook Calendar Rest API (create meeting using /me/events request with change organizer)
outlook.com rest api incorrect organizer email
How to create event where current user not organizer using Microsoft Graph API

Slack Bot Interactive Message. Showing "Oh no, something went wrong. Please try that again." on button click

I have a slack bot where I am sending structured message using Tester on chat.postMessage() using Developer account for Slack App.
Message gets sends smoothly, but when button is clicked it shows-
"Oh no, something went wrong. Please try that again." in the chat window and nothing recieved on Interactive Message Request URL.
I am out of clue what is happening, Any help will be appreciated.
Message attachment
[
{
"title": "The Further Adventures of Slackbot",
"fields": [
{
"title": "Volume",
"value": "1",
"short": true
},
{
"title": "Issue",
"value": "3",
"short": true
}
],
"author_name": "Stanford S. Strickland",
"author_icon": "http://a.slack-edge.com/7f18/img/api/homepage_custom_integrations-2x.png",
"image_url": "http://i.imgur.com/OJkaVOI.jpg?1"
},
{
"title": "Synopsis",
"text": "After #episod pushed exciting changes to a devious new branch back in Issue 1, Slackbot notifies #don about an unexpected deploy..."
},
{
"fallback": "Would you recommend it to customers?",
"title": "Would you recommend it to customers?",
"callback_id": "comic_1234_xyz",
"color": "#3AA3E3",
"attachment_type": "default",
"actions": [
{
"name": "recommend",
"text": "Recommend",
"type": "button",
"value": "recommend"
},
{
"name": "no",
"text": "No",
"type": "button",
"value": "bad"
}
]
}
]
it is sorted now. Actually I was using wrong token, test token, where a bot access token or user access token obtained through the app's OAuth flow must be used.

Resources