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

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"
}
]
}

Related

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

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%"
}
}
]
}

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>"
}
}]
}

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.

Azure LogicApp with Conditional Control is not working

My Service Bus queue is receiving telemetry of 2 different objects. For Object1 is have to send mail to MailId1 and for Object2 j have to send mail to MailId2. Also, I have to use some of the content from JSON telemetry as the body of my mail.
For a single object, it is working fine. In my logic app, I have used service bus (its queue is receiving telemetry messages) followed by parse JSON (to parse content as JSON) and lastly SMTP to send mail. In case I need to make decisions based on JSON, what workflow can I use in LogicApp?
I have used Condition action as shown in the image below.
JSON parsed in IF condition is
{
"properties": {
"dbt": {
"type": "integer"
},
"latitude": {
"type": "number"
},
"location": {
"type": "string"
},
"longitude": {
"type": "number"
},
"owner": {
"type": "string"
},
"speed": {
"type": "integer"
},
"stdb": {
"type": "integer"
},
"timeCreated": {
"type": "integer"
}
},
"type": "object"
}
JSON parsed in ELSE condition
{
"properties": {
"message": {
"type": "string"
},
"owner": {
"type": "string"
},
"timeCreated": {
"type": "integer"
}
},
"type": "object"
}
For either of the telemetry, the condition always fails and executes else part. IF part is never executed. Where am I going wrong in setting condition for IF part?
Any help would be appropriated.
You can use conditional statements.

Resources