How to retrieve Status of each test cases in TestRail via Webhook? - webhooks

Anyone has experience using TestRail? I am trying to use this payload webhook with Slack and each time when I update my test case, the status is always null. How can i make sure it reads properly (ie Passed, Failed, Disabled)
{
"text": "%event_creator% created a new test case:",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*%event_creator% created a new test case:*"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<%url%|%name%>* \n Priority: %case_priority% \n Status: %stats%"
}
}
]
}

Related

I am getting invalid_blocks_format while trying to post a message to slack

I am trying to post a message to slack using node.js but I got invalid_blocks_format error. In the slack API reference says that: this error occurs because of invalid JSON or wrong Block KIT syntax. I have checked both and everything seems correct. An example of my payload:
{
"channel": "CHANNELID",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Someone* just replied"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Email:*\n<https://example.com/some-url?query-param=value|someone#email.com>"
},
{
"type": "mrkdwn",
"text": "*Campaign:*\n<https://example.com/some-url|Name - Some value>"
},
{
"type": "mrkdwn",
"text": "*Replying To:*\nanotheremail.com"
},
{
"type": "mrkdwn",
"text": "*Assigned To:*\nName Surname"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ">Stop\n>\n>On Aug 8, 2022, at 6:40 PM, Sender <sender#email.com> wrote:\n>\n> Hi Someone,\n>\n>My name is Name from A company.\n>\n>Some content\n> \n>Content continues(https://blog.example.com/ulr?query-param=value) Content. \n>Would you like to book a demo?(https://example.com/url) \n>Let me know and I’ll schedule it.\n>\n>\n>Name Surname\n>Customer Success Manager\n>Company Name\n>\n> \n>\n>\n>\n>CONFIDENTIALITY NOTICE: This message, including any attachments, is the property of Company name Ltd., its affiliates and/or subs"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Recipient"
},
"action_id": "view",
"url": "https://example.com/view?query=asd",
"style": "primary"
},
{
"type": "static_select",
"placeholder": {
"type": "plain_text",
"text": "Set lead status"
},
"action_id": "set-lead-status",
"options": [
{
"text": {
"type": "plain_text",
"text": "Open Lead"
},
"value": "env=prod;recipientID=1234567;leadStatus=Open"
},
{
"text": {
"type": "plain_text",
"text": "Ignore Lead"
},
"value": "env=prod;recipientID=1234567;leadStatus=Ignored"
},
{
"text": {
"type": "plain_text",
"text": "Lost Lead"
},
"value": "env=prod;recipientID=1234567;leadStatus=Lost"
},
{
"text": {
"type": "plain_text",
"text": "Won Lead"
},
"value": "env=prod;recipientID=1234567;leadStatus=Closed"
}
]
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Pause Recipient"
},
"action_id": "pause",
"value": "env=prod;recipientID=1234567;"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Unsubscribe"
},
"action_id": "unsubscribe",
"value": "env=prod;recipientID=1234567;",
"style": "danger",
"confirm": {
"title": {
"type": "plain_text",
"text": "Unsubscribe recipient"
},
"text": {
"type": "plain_text",
"text": "Are you sure you want to unsubscribe email#address.com?"
},
"confirm": {
"type": "plain_text",
"text": "Yes"
},
"deny": {
"type": "plain_text",
"text": "Cancel"
}
}
}
]
}
],
"token": "token-value"
}
Also when I try to post this over https://app.slack.com/block-kit-builder, message posted without any problem. What can be the problem and how can I fix it?
Thanks for any help/suggestion.
UPDATE
I figured out the problem but not the solution.
Problem is url's with more than one query parameters. If any text has a link like;
https://example.com/url?param1=value1&param2=value2
Sources suggested to encode texts but if I do that, slack prints it without decode it. So sent message is not readable. I am still open to suggestions.
Channel should not be inside the block but as a property while using the Slack API.
Exemple using Slack WebClient in node.js:
client.chat.postMessage({
channel: 'channelId',
blocks: 'yourBlock',
});
I was using an old version of slack lib on node and messages contain ampersand (&) caused the problem like links with more than one query parameters. Updating library solved my problem.

How can I add unfurl_links in Slack message

In the Slack message format example block below, how can I add unfurl_link option?
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "New Paid Time Off request from <example.com|Fred Enriquez>\n\n<https://example.com|View request>"
}
}
I'm guessing the snippet you posted is part of the blocks parameter, try adding the unfurl_links parameter with a value of false (outside the blocks):
{
"token": "your-slack-token",
"channel": "#test-channel",
"unfurl_links": false,
"blocks": [{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "New Paid Time Off request from <example.com|Fred Enriquez>\n\n<https://example.com|View request>"
}
}]
}

Slack webhook doesn't accept a JSON payload with a block that has an empty string

I am trying to set up an integration between Zendesk and Slack, where Zendesk sends new notifications to Slack using Slack's Incoming Webhooks. The issue is that under certain circumstances, some Zendesk fields would be empty strings, which are flagged by slack as an invalid_payload. I would love to be able to send the message with an empty string, or at least have a fallback string if the zendesk field is empty.
I have confirmed that populating the empty string, without making any other changes to the payload, results in a successful integration, so it's definitely the empty string blocking the message from being delivered. I have also found this SO thread, but this doesn't seem to work for me. I haven't been able to find any documentation from slack regarding empty strings in the JSON payload either.
So I guess my question is whether or not it's possible to send empty strings in a JSON payload for Slack webhooks at all, and if not, is there a workaround to account for the possibility of an empty string? As I mentioned, this is a Zendesk integration so I don't have the ability to write a script to check for an empty string because it's all happening within Zendesk's dashboard (at least as far as I'm aware).
Here's the overall JSON object that I am trying to send from Zendesk to Slack. The Organization field is the one that has the potential to be blank:
{
"blocks": [
{
"type": "divider"
},
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Ticket Title/Subject"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "*Ticket #_000_*"
}
]
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "*Status: _New_*"
}
]
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Requester*"
},
{
"type": "mrkdwn",
"text": "*Organization*"
},
{
"type": "plain_text",
"text": "Client Name"
},
{
"type": "plain_text",
"text": "Organization Name" //Possible empty string
}
]
},
{
"type": "section",
"text": {
"type": "plain_text",
"text": "Message Body Text Here"
}
},
{
"type": "divider"
}
]
}

Use "response_action" to respond to view_submission when using botkit

I have a simple modal with view pushed using:
const result = await bot.api.views.open({
trigger_id: message.trigger_id,
view: {
"type": "modal",
"submit": {
"type": "plain_text",
"text": "Submit",
"emoji": true
},
"title": {
"type": "plain_text",
"text": "Request",
"emoji": true
},
"blocks": [
{
"type": "input",
"block_id" : "accblock",
"element": {
"type": "plain_text_input",
"action_id": "account_name",
"multiline": false
},
"label": {
"type": "plain_text",
"text": "Account Name",
"emoji": true
}
}
]
}
});
I need to add error to the block if certain value is entered on view_submission. I understand I should send response with the following JSON:
{
response_action: 'errors',
errors: {
"ticket-desc": 'I will never accept a value, you are doomed!'
}
}
But, how do I send it? I've tried using bot.httpBody(). Does this JSON need to be included as the view object? Any help is appreciated.
bot.httpBody() is the method you need.
Make sure that the key to the errors dictionary matches the block_id of the element you are providing an error message for.
In your case this will work:
bot.httpBody({
response_action: 'errors',
errors: {
accblock: 'Your account name is invalid or in use.'
}
})
You do not need to JSON.stringify the response message and indeed the process fails if you do.

Adaptive card in teams not workig - REST API

I created a bot (nodejs server) for teams - through bot framework.
I'm trying to send adaptive card that I created through: adaptive cards designer
and I get error :
{"code":"BadArgument","message":"ContentType of an attachment is not set"}
The request body :
{
"type": "message",
"from": {
"id": "xxxxxx"
},
"conversation": {
"id": "xxxxxx"
},
"recipient": {
"id": "xxxxx"
},
"replyToId": "xxxxx",
"text": "some text",
"attachments": [
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.2",
"body": [
{
"type": "TextBlock",
"text": "some text"
},
{
"type": "Input.Date",
"separator": true
}
]
}
]
}
I would appreciate help
When adding attachments you'll want to set the contentType and content properties of the attachment object.
https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-api-reference?view=azure-bot-service-4.0#attachment-object
{
"type": "message",
"from": {
"id": "xxxxxx"
},
"conversation": {
"id": "xxxxxx"
},
"recipient": {
"id": "xxxxx"
},
"replyToId": "xxxxx",
"text": "some text",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.2",
"body": [
{
"type": "TextBlock",
"text": "some text"
},
{
"type": "Input.Date",
"separator": true
}
]
}
}
]
}
As per the comments above, this is a pro-active message, but using the Bot Framework libraries are a much better approach than trying to call the bot endpoints directly (I wondered if, by "REST", you meant the Bot Framework endpoint or the Graph Api, but in either case the Bot Framework is easier to work with for proactive messages).
Please see specifically this sample for how to do this in Node.

Resources