How to create zoom like response in slack bot message using block kit? - slack-api

I have used zoom integration with slack. When I send /zoom command the bot responds with a new meeting link in a box layout that looks really good.
Note the bordered box below "Call"
However I am not able to create similar box layout with border and section in my own slack bot. Which block kit syntax should I use to achieve the same design?
At max what I am able to achieve is like the below:
I did not find any relevant example in the documentation as well.

There are multiple ways suggested in slack's official documentation to format Messages in responses.
For instance:
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hello, Assistant to the Regional Manager Dwight! *Michael Scott* wants to know where you'd like to take the Paper Company investors to dinner tonight.\n\n *Please select a restaurant:*"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Farmhouse Thai Cuisine*\n:star::star::star::star: 1528 reviews\n They do have some vegan options, like the roti and curry, plus they have a ton of salad stuff and noodles can be ordered without meat!! They have something for everyone here"
},
"accessory": {
"type": "image",
"image_url": "https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg",
"alt_text": "alt text for image"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Kin Khao*\n:star::star::star::star: 1638 reviews\n The sticky rice also goes wonderfully with the caramelized pork belly, which is absolutely melt-in-your-mouth and so soft."
},
"accessory": {
"type": "image",
"image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/korel-1YjNtFtJlMTaC26A/o.jpg",
"alt_text": "alt text for image"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Ler Ros*\n:star::star::star::star: 2082 reviews\n I would really recommend the Yum Koh Moo Yang - Spicy lime dressing and roasted quick marinated pork shoulder, basil leaves, chili & rice powder."
},
"accessory": {
"type": "image",
"image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/DawwNigKJ2ckPeDeDM7jAg/o.jpg",
"alt_text": "alt text for image"
}
},
{
"type": "divider"
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Farmhouse",
"emoji": true
},
"value": "click_me_123"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Kin Khao",
"emoji": true
},
"value": "click_me_123",
"url": "https://google.com"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Ler Ros",
"emoji": true
},
"value": "click_me_123",
"url": "https://google.com"
}
]
}
]}
You can use these components to design your own experience in response.
Further reading: https://api.slack.com/messaging/composing

I think the elements you are referring to are produced by the Call API
It doesn't seem that it is an available block for use in message building.

Related

Send Jira Issue Description text as ADF table in Jira REST API

I am trying to update an issue description by sending an ADF table. My javascript code is as follows.
{
"fields" : {
"description": {
"version": 1,
"type": "doc",
"content": [
{
"type": "table",
"attrs": {
"isNumberColumnEnabled": false,
"layout": "default"
},
"content": [
{
"type": "tableRow",
"content": [
{
"type": "tableCell",
"attrs": {},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": " Row one, cell one"
}]
}]
},
{
"type": "tableCell",
"attrs": {},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Row one, cell two"
} ]
}]
}]
}]
}]
}
}
}
The error that I get back is "description":"Operation value must be a string". Not sure what I am doing wrong as it looks like I have the ADF formatting correct.
This is calling jira cloud via the rest api.
Found the answer. The URL must be version 3 of the API. Just have "latest" will not work. Example:
https://mycompay.atlassian.net/rest/api/3/issue/45379
and not
https://mycompany.atlassian.net/rest/api/latest/issue/45379

Slack client.views.update not maintaining selected input values

I am updating slack modal view but it doesn't maintain selected dropdown values, on every update modal is getting reinitialized.
I want to select dropdown one and based on selection looking to populate dropdown two and on update all selected values should be maintain in the modal view.
Seeking assistance to make interactive modal view.
await client.views.update({
token: process.env.SLACK_BOT_TOKEN,
hash: view.hash,
view_id: view.id,
view: await moduleBlocks()
});
moduleBlocks (){
const modal = {
"callback_id": "create-incident-modal",
"type": "modal",
"title": {
"type": "plain_text",
"text": "Create Incident"
},
"submit": {
"type": "plain_text",
"text": "Submit"
},
"blocks": [
{
"type": "input",
"dispatch_action": true,
"element": {
"type": "static_select",
"placeholder": {
"type": "plain_text",
"text": "Select an item",
"emoji": true
},
"options": [
{
"text": {
"type": "plain_text",
"text": "*option 1*",
"emoji": true
},
"value": "value-0"
},
{
"text": {
"type": "plain_text",
"text": "*option 2*",
"emoji": true
},
"value": "value-1"
},
{
"text": {
"type": "plain_text",
"text": "*option 3*",
"emoji": true
},
"value": "value-2"
}
],
"action_id": "static_select-1"
},
"label": {
"type": "plain_text",
"text": "Label",
"emoji": true
}
},
{
"type": "input",
"dispatch_action": true,
"element": {
"type": "static_select",
"placeholder": {
"type": "plain_text",
"text": "Select an item",
"emoji": true
},
"options": [
{
"text": {
"type": "plain_text",
"text": "*option2 1*",
"emoji": true
},
"value": "value-0"
},
{
"text": {
"type": "plain_text",
"text": "*option2 2*",
"emoji": true
},
"value": "value-1"
},
{
"text": {
"type": "plain_text",
"text": "*option3 3*",
"emoji": true
},
"value": "value-2"
}
],
"action_id": "static_select-2"
},
"label": {
"type": "plain_text",
"text": "Label",
"emoji": true
}
}
]
}
return JSON.stringify(modal);
}
Your blocks need a set block_id to maintain the same values. When you don't provide a block_id, a block_id is generated for you. When slack sees the block_id change, it resets the values.
"type": "input",
"dispatch_action": true,
"block_id": "test_id"
"element": {
When you update the each time, keep block_id the same except for the block you want to update.
Here is some info on blocks & block_id: https://api.slack.com/reference/block-kit/blocks

How do you get the side color bar to work for Slack notification attachments?

I'm POSTing the following test json to a Slack Webhook Url:
{
"attachments": [
{
"blocks": [
{
"type": "divider"
},
{
"text": {
"text": "This is error 1",
"type": "plain_text"
},
"type": "section"
},
{
"type": "divider"
},
{
"text": {
"text": "This is error 2",
"type": "plain_text"
},
"type": "section"
},
{
"type": "divider"
},
{
"text": {
"text": "This is error 3",
"type": "plain_text"
},
"type": "section"
}
],
"color": "danger"
}
],
"blocks": [
{
"text": {
"text": "*Failed*\nDeploy <https://google.com|Test>\nTotal tests: 75 Passed: 75 Total time: 54.1872 Seconds\nError Messages:",
"type": "mrkdwn"
},
"type": "section"
}
]
}
As you can see in the payload, I'm setting "color": "danger" in the attachment object, which should result in a red color bar on the notification according to Slack's documentation. However, the Slack notification just has the default gray color bar. What am I doing wrong?

how to send message to whole width in slack?

I have a question related to sending a message to Slack from Jenkins (groovy script).
Currently, I use SlackNotificationPlugin for sending messages to Slack and I'm trying to send line for the whole width of Slack, but instead of it, I can use only half of Slack width.
I use code below:
msg = readJSON text: """
{
"pretext": "<placeholder>",
"text": "<placeholder>",
"color": "good",
"mrkdwn_in": [
"pretext",
"text"
],
"fields": [
{
"title": "A field's title",
"value": "This field's valueaaaaaaaaaaaa valueaaaaaaaaaaaa valueaaaaaaaaaaaa valueaaaaaaaaaaaa valueaaaaaaaaaaaa valueaaaaaaaaaaaa valueaaaaaaaaaaaa",
"short": false
},
{
"title": "A short field's title",
"value": "A short field's value",
"short": true
},
{
"title": "A second short field's title",
"value": "A second short field's value",
"short": true
}
],
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Alternative hotel options*"
}
}
]
}
"""
msg.pretext = pretext.inspect()
msg.text = text.inspect()
slack_channel = partner_channel
slackSend(channel: slack_channel, color: 'good', attachments: "[${msg.toString()}]")
On the screenshot below you can see Packages Difference and it showed only on the half of the page.
I found a solution for this case and I tested it in Slack Block Kit Builder:
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "```{8}```"
}
}
]
}
https://app.slack.com/block-kit-builder/T025QN6JG#%7B%22blocks%22:%5B%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22%60%60%60%7B8%7D%60%60%60%22%7D%7D%5D%7D
It Slack Block Kit Builder, I can successfully send a message and use the whole space of slack:
In official documentation for Jenkins Slack Plugin (https://plugins.jenkins.io/slack/), I found that for sending blocks we can use the next construction:
blocks = [
[
"type": "section",
"text": [
"type": "mrkdwn",
"text": "Hello, Assistant to the Regional Manager Dwight! *Michael Scott* wants to know where you'd like to take the Paper Company investors to dinner tonight.\n\n *Please select a restaurant:*"
]
],
[
"type": "divider"
],
[
"type": "section",
"text": [
"type": "mrkdwn",
"text": "*Farmhouse Thai Cuisine*\n:star::star::star::star: 1528 reviews\n They do have some vegan options, like the roti and curry, plus they have a ton of salad stuff and noodles can be ordered without meat!! They have something for everyone here"
],
"accessory": [
"type": "image",
"image_url": "https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg",
"alt_text": "alt text for image"
]
]
]
slackSend(channel: "#general", blocks: blocks)
The mentioned code doesn't work for me I have nothing in Slack when I use block construction.
Can somebody help me with it? I don't use any Bot User, I just want to send the output of Jenkins to Slack.
Thanks in advance.

Slack API invalid_block

I'm building a simple slack bot and I am playing with the checkboxes element.
When I return the following from my API in a JSON response to a slash-command I get an error failed with the error "invalid_blocks", however, when I put this in the block-kit-builder it works perfectly (including "sending to slack" button)
Any ideas why this is failing when I run my slash command - and is it possible to see more detailed error messages from slack?
{
"blocks": [
{
"elements": [
{
"style": "primary",
"text": {
"emoji": true,
"text": "Create new TODO list",
"type": "plain_text"
},
"type": "button",
"value": "value"
},
{
"style": "primary",
"text": {
"emoji": true,
"text": "Help",
"type": "plain_text"
},
"type": "button",
"value": "value"
}
],
"type": "actions"
},
{
"text": {
"text": "Today",
"type": "mrkdwn"
},
"type": "section"
},
{
"elements": [
{
"initial_options": [
{
"text": {
"text": "Get Into the garden",
"type": "mrkdwn"
},
"value": "foo"
}
],
"options": [
{
"text": {
"text": "Get Into the garden",
"type": "mrkdwn"
},
"value": "foo"
}
],
"type": "checkboxes"
},
{
"style": "primary",
"text": {
"emoji": true,
"text": "Add new Task",
"type": "plain_text"
},
"type": "button",
"value": "value"
}
],
"type": "actions"
}
],
"type": "home"
}
I am using the Slack Web API. I was getting the similar error. After a lot of looking around, here's how I solved it.
import json
blocks = [{...}]
payload = {
"blocks": json.dumps(blocks)
}
You will then send this payload.
in the api, the "blocks" parameter need to be string type. Did you convert it to string or you use it as a JSON ?
https://api.slack.com/methods/chat.postMessage
In the Block Kit Builder, the data is a JSON with a blocks key.
In the Slack API, the blocks param is only the list of JSON objects.
blocks = [
{
"text": {
"text": "Its the list of your blocks",
"type": "mrkdwn"
},
"type": "section"
}
]
text = 'Alternative data in text'
client.chat_postMessage(channel=channel_id, blocks=blocks, text=text)
Another cause of this problem seems to be too many blocks being returned. I can't find any documentation about this whatsoever, but personal experience seems to indicate about 20 blocks is the maximum.
An alternative is to return fewer blocks, with paging actions -- paging works well with the "replace" message so that the content being paged through does not result in many separate messages.
It appears that not all valid elements in block kit tool can be posted as a message, despite the fact that message preview works fine in the Block Tool.
In my case, the code failed when I included an input block and passed when i removed it. The input block was generated by the Block Kit tool.
{
"type": "input",
"element": {
"type": "plain_text_input",
"action_id": "plain_text_input-action"
},
"label": {
"type": "plain_text",
"text": "Feedback",
"emoji": true
}
}
The error was
{'ok': False, 'error': 'invalid_blocks'}
Also, although the documentation for python says you need to urlEncode the JSON-based array, there is no example, and it is incorrect. https://api.slack.com/methods/chat.postMessage
You can see on line 29 in the SDK test code below that blocks= takes a regular list of dicts not a string.
https://github.com/slackapi/python-slack-sdk/blob/c9dc6aa0907a72c16cf36aa15e7e80031a9fdce2/integration_tests/samples/basic_usage/sending_a_message.py

Resources