How to delete message replies using Slack API? - slack-api

I'm getting an error when I try to use Slack API to remove the replies saying the channel doesn't exists.
To validate it, I'm calling the:
https://slack.com/api/channels.history?token={token}&channel={channel}&count=1&inclusive=true&latest={ts}&oldest={ts}
Then I get the message back.
The message I'm getting back is this one:
{
"ok": true,
"latest": "1540555927.024300",
"oldest": "1540555927.024300",
"messages": [
{
"text": "This message was deleted.",
"edited": {
"user": "UD6SLKGEP",
"ts": "1540555928.000000"
},
"type": "message",
"subtype": "tombstone",
"user": "USLACKBOT",
"hidden": true,
"thread_ts": "1540555927.024300",
"reply_count": 1,
"replies": [
{
"user": "UD6SLKGEP",
"ts": "1540555928.024401"
}
],
"subscribed": false,
"unread_count": 1,
"ts": "1540555927.024300"
}
],
"has_more": false,
"is_limited": true
}
As you can see, there is this "This message was deleted." that seems to be generated automatically and keep showing up because I still have replies associated to it.
If I call the same endpoint passing the reply ts (1540555928.024401), for the same channel I get this:
{
"ok": true,
"latest": "1540555928.024401",
"oldest": "1540555928.024401",
"messages": [
{
"type": "message",
"user": "UD6SLKGEP",
"text": "45d7bc14a6fa03 23456789 abcdefghijklmnop",
"bot_id": "BD6AJUY8G",
"thread_ts": "1540555927.024300",
"ts": "1540555928.024401"
}
],
"has_more": false,
"is_limited": true
}
Which means that there is a message there, which is a reply from another message.
The problem starts when I try to remove this reply message.
I call this endpoint:
https://slack.com/api/chat.delete?token={token}
Passing the channel and the reply ts as the payload:
{
"channel": "CD65XB2D7",
"message_ts": "1540555928.024401"
}
Now instead of having the message removed, I get this response:
{
"ok": false,
"error": "channel_not_found",
"warning": "missing_charset",
"response_metadata": {
"warnings": [
"missing_charset"
]
}
}
But the channel exists and I'm using it to remove other messages as well. That happens when I try to remove the reply from a message only.
Is there something special about removing reply messages?

I just found out the problem here:
https://api.slack.com/changelog/2017-10-keeping-up-with-the-jsons#methods
For some reason on my side it's working for messages, but not for replies. I had to move the token to the "Authorization" on header with the Bearer as suggested on this link.

Related

I am trying to add forwarding rule to the user's mailbox but it is not working asexpected

I am using graph API to add message rule which is forward a mail from user's inbox. Rule is getting added but mails are not forwarding to specified id.
Here are some details:
var data = {
"displayName": "From partner",
"sequence": 1,
"isEnabled": true,
"conditions": {
"isAutomaticForward": true
},
"actions": {
"forwardTo": [
{
"emailAddress": {
"name": "recipient name ",
"address": "email address"
}
}
],
"stopProcessingRules": true
}
}
axios.post("https://graph.microsoft.com/v1.0/users/{userId}/mailFolders/inbox/messageRules", data,
{
headers: {
"Authorization": "Bearer " + access_token
}
}
)
.then(response => {
console.log(response.data)
})
.catch(err => {
console.log(err.response)
})
Response is as expected but mails are not forwarding.
I tried the above payload, steps and it works for me!!
(1) Create a new rule using Graph API
POST https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messageRules
Content-type: application/json
{
"displayName": "From partner",
"sequence": 2,
"isAutomaticForward": true,
"actions": {
"forwardTo": [
{
"emailAddress": {
"name": "Alex Wilbur",
"address": "AlexW#contoso.onmicrosoft.com"
}
}
],
"stopProcessingRules": true
}
}
(2) Test whether the rule is working or not.
Result: It's working as expected
(3) Check that the above rule shows or not (as part of Outlook.office.com or Outlook UI's rule section)
Adding a snapshot that i captured from Outlook.office.com, mailbox settings!!

Apache Ranger REST API addUsersAndGroups returns 404 not found

We have installed Apache Ranger and the Web UI works fine, most of the REST API method works fine on both PublicAPIsv2 and RoleREST as per https://ranger.apache.org/apidocs/ui/index.html.
I can get “test_role” id by calling GET /public/v2/api/roles/name/test_role which returns the id 409.
I can get test_role content by calling GET /public/v2/api/roles/409
I can change test_role users list by editing the response I get from GET /public/v2/api/roles/409 and submitting it through PUT /public/v2/api/roles/409
The body is:
{
"id": 409,
"isEnabled": true,
"createdBy": "admin",
"updatedBy": "admin",
"createTime": 1598241102841,
"updateTime": 1601975068428,
"name": "test_role",
"options": {},
"users": [
{
"name": "test_user1”,
"isAdmin": true
},
{
"name": “test_user2”,
"isAdmin": true
},
{
"name": “test_user3”,
"isAdmin": false
}
],
"groups": [
{
"name": "test_group”,
"isAdmin": false
}
],
"roles": []
}
But calling PUT /public/v2/api/roles/409/addUsersAndGroups returns “404 not found”.
I tried with the same body as above as parameter, and also with:
{
"users": [
{
"name": “test_user4”,
"isAdmin": true
}
]
}
Would anybody know what is the correct body to send as parameter to:
/public/v2/api/roles/409/addUsersAndGroups?
Also, making a wrong call such as GET /public/v2/api/roles/409/addUsersAndGroups returns “405 method not allowed”. So I believe it shows the end point does exist. I’m not sure why calling PUT public/v2/api/roles/409/addUsersAndGroups with (probably) incorrect body returns “404 not found” and not an error message related to the wrong parameter.
It happens because Apache Ranger API documentation is wrong, remove the suffix /addUsersAndGroups of your endpoint and it will work.
Example: https://ranger_url/service/roles/roles/409
Where 409 is the role ID, as you're using on your example.
The body that is needed:
{
"name": "test_role",
"users": [
{
"name": "test_user1",
"isAdmin": true
}
]
}

Azure Logic App: Read telemetry data as dynamic content from IoT hub message

I'm routing telemetry messages via IoT Events and event Grid to Logic Apps using a webhook. The logic app lets you input a sample JSON message and then use dynamic content to add information to an email alert I'm sending(O365: Send an Email V2)
I can include System Properties like "iothub-connection-device-id" But when I try to pick temeletry data I get the following error:
InvalidTemplate. Unable to process template language expressions in action 'Send_an_email_(V2)' inputs at line '1' and column '1680': 'The template language expression 'items('For_each')?['data']?['body']?['windingTemp1']' cannot be evaluated because property 'windingTemp1' cannot be selected. Property selection is not supported on values of type 'String'. Please see https://aka.ms/logicexpressions for usage details.'.
When I look at the raw output of the webhook connector it shows the following message but the telemetry points are cleary not there. I'd expect to see them in the "body" property but instead there is just the string: "eyJ3aW5kaW5nVGVtcDEiOjg2LjYzOTYxNzk4MjYxODMzLCJ3aW5kaW5nVGVtcDIiOjc4LjQ1MDc4NTgwMjQyMTUyLCJ3aW5kaW5nVGVtcDMiOjg1LjUzMDYxMDY5OTQ1MzY1LCJMb2FkQSI6MjAyOS44NDgyMTg4ODYxMTEsIkxvYWRCIjoyMDQwLjgxMDk4OTg0MDMzMzgsIkxvYWRWIjoyMDA0LjYxMTkzMjMyNTQ2MTgsIk9pbFRlbXAiOjk5LjA2MjMyNjU2MTY4ODU4fQ=="
Looking for help to determine what could be causing this and how to get the telemetry data passed through correctly so that I can inculde it dynamically in the email alert.
Thanks!
{
"headers": {
"Connection": "Keep-Alive",
"Accept-Encoding": "gzip,deflate",
"Host": "prod-24.northeurope.logic.azure.com",
"aeg-subscription-name": "TEMPALERT",
"aeg-delivery-count": "1",
"aeg-data-version": "",
"aeg-metadata-version": "1",
"aeg-event-type": "Notification",
"Content-Length": "1017",
"Content-Type": "application/json; charset=utf-8"
},
"body": [
{
"id": "c767fb91-3806-324c-ec3c-XXXXXXXXXX",
"topic": "/SUBSCRIPTIONS/XXXXXXXXXXXX",
"subject": "devices/Device-001",
"eventType": "Microsoft.Devices.DeviceTelemetry",
"data": {
"properties": {
"TempAlarm": "true"
},
"systemProperties": {
"iothub-connection-device-id": "Device-001",
"iothub-connection-auth-method": "{\"scope\":\"device\",\"type\":\"sas\",\"issuer\":\"iothub\",\"acceptingIpFilterRule\":null}",
"iothub-connection-auth-generation-id": "637264713410XXXX",
"iothub-enqueuedtime": "2020-06-01T23:05:58.3130000Z",
"iothub-message-source": "Telemetry"
},
"body": "eyJ3aW5kaW5nVGVtcDEiOjg2LjYzOTYxNzk4MjYxODMzLCJ3aW5kaW5nVGVtcDIiOjc4LjQ1MDc4NTgwMjQyMTUyLCJ3aW5kaW5nVGVtcDMiOjg1LjUzMDYxMDY5OTQ1MzY1LCJMb2FkQSI6MjAyOS44NDgyMTg4ODYxMTEsIkxvYWRCIjoyMDQwLjgxMDk4OTg0MDMzMzgsIkxvYWRWIjoyMDA0LjYxMTkzMjMyNTQ2MTgsIk9pbFRlbXAiOjk5LjA2MjMyNjU2MTY4ODU4fQ=="
},
"dataVersion": "",
"metadataVersion": "1",
"eventTime": "2020-06-01T23:05:58.313Z"
}
]
}
Here is the sample input I am using with the trigger:
[{
"id": "9af86784-8d40-fe2g-8b2a-bab65e106785",
"topic": "/SUBSCRIPTIONS/<subscription ID>/RESOURCEGROUPS/<resource group name>/PROVIDERS/MICROSOFT.DEVICES/IOTHUBS/<hub name>",
"subject": "devices/LogicAppTestDevice",
"eventType": "Microsoft.Devices.DeviceTelemetry",
"eventTime": "2019-01-07T20:58:30.48Z",
"data": {
"body": {
"windingTemp1": 95.62818310718433
},
"properties": {
"Status": "Active"
},
"systemProperties": {
"iothub-content-type": "application/json",
"iothub-content-encoding": "utf-8",
"iothub-connection-device-id": "d1",
"iothub-connection-auth-method": "{\"scope\":\"device\",\"type\":\"sas\",\"issuer\":\"iothub\",\"acceptingIpFilterRule\":null}",
"iothub-connection-auth-generation-id": "123455432199234570",
"iothub-enqueuedtime": "2019-01-07T20:58:30.48Z",
"iothub-message-source": "Telemetry"
}
},
"dataVersion": "",
"metadataVersion": "1"
}]
Summary comment to answer to help others who have same problem.
The body you provided is Base64 encoded, you can decode it with Convert.FromBase64String(String) Method.
byte[] newBytes = Convert.FromBase64String(body);
For more details, you could refer to this issue.
Update:
Add the following code in my application will solve the problem.
message.ContentEncoding = "utf-8";
message.ContentType = "application/json";

Sonar Qualitygate api based on Severity [blocker/critical/major] not on Type[bugs/vulnerability/code-smells]

I am hitting sonar api (api/qualitygates/project_status?analysisId=xyz) from pipeline based on analysisId to get the project status. The response recevied is based on Type[bugs/vulnerability/code-smells]
Is it possible to get the status based on Severity [blocker/critical/major] ?
{
"projectStatus": {
"status": "ERROR",
"conditions": [
{
"status": "OK",
"metricKey": "bugs",
"comparator": "GT",
"errorThreshold": "0",
"actualValue": "0"
},
{
"status": "ERROR",
"metricKey": "vulnerabilities",
"comparator": "GT",
"errorThreshold": "0",
"actualValue": "31"
},
{
"status": "ERROR",
"metricKey": "code_smells",
"comparator": "GT",
"errorThreshold": "0",
"actualValue": "72"
}
],
"periods": [
],
"ignoredConditions": false
}
}
Here how I got the status, may help someone who is struggling with this issue.
The trick it to use short-lived branch-name instead of using the analysisId on following api-
http://sonardashboard.xxx.com/api/issues/search?componentRoots=<Project-key>&severities=<Type of severity>&branch=<short-lived branch name>
Note: This will give issues with status - open and closed. Couldn't filter out using api based on status though.

Unknown name \"model\" at 'config': Cannot find field

I'm trying to use Google Cloud speech (v1beta1) to analyse phone calls. I can't find the "model" parameter in the C# client library, so I'm constructing my own json message and sending it. This works:
{
"audio": {
"content": "UklGRiavCAA+P8QAAgA....."
},
"config": {
"languageCode": "nl-NL"
}
}
But when I add the phone_call model like this:
{
"audio": {
"content": "UklGRiavCAA+P8QAAgA....."
},
"config": {
"languageCode": "nl-NL",
"model": "phone_call"
}
}
I get an error:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"model\" at 'config': Cannot find field.",
"errors": [
{
"message": "Invalid JSON payload received. Unknown name \"model\" at 'config': Cannot find field.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
Why? Accoding to the documentation I believe my request is valid?
Edit: to answer my own question: turns out I was using a wrong url. The correct url is: https://speech.googleapis.com/v1p1beta1/speech:recognize.
I'm sorry to be the bearer of bad news, but it looks like the phone call model is only supported for en-US, and your language is nl-NL:
https://cloud.google.com/speech-to-text/docs/basics
Scroll down to "Selecting Models". "Command and Search" and "Default" are both listed as available for all languages, but "video" and "phone call" are listed as "en-US only".

Resources