I have a slack modal with a static_select
{
block_id: "my_block_id",
type: "section",
text: {
type: "mrkdwn",
text: "Please select one"
},
accessory: {
type: "static_select",
action_id: "select_type",
placeholder: {
type: "plain_text",
text: "Select one"
},
options: self.types_options
}
},
When the user selects one of the option a backend call is been triggered, can I avoid that and have the call triggered on submit form button click?
Put your static_select inside an input rather than a section.
When someone uses an interactive component in your app's modal views,
the app will receive a block_actions payload.
This does not apply to components included in an input block (see
below for details about those).
https://api.slack.com/surfaces/modals/using#components
Any interactive components used within input blocks will not send this block_actions payload. They are included in view_submission payloads only.
https://api.slack.com/reference/interaction-payloads/block-actions
Yes, but not within a normal message.
Instead you want to use a Modal. Models are modal dialogs, which have a submit button and can have multiple input elements.
Related
My app shows a simple PlainTextInput with a button in a message (Not modal).
And I would like to receive entered data by user after receiving button pressed action.
Based on slack docs, Plain-text input elements are supported in the following app surfaces: Home tabs, Messages,Modals but I don't know how to read this value from input text when using it in message (Direct message of my app and user)!
In dialog, I can easily read this value after view submission from ViewOutput data, but for messages, when reading received body data (body.message.blocks) , I have this
{
type: 'input',
block_id: 'chapterTitleInputBlock',
label: { type: 'plain_text', text: 'Chapter title', emoji: true },
optional: false,
dispatch_action: false,
element: {
type: 'plain_text_input',
action_id: 'chapter_title_input-action',
dispatch_action_config: [Object]
}
}
Which doesn't have a text field for entered value by user, how to get this value?
I should use PlainTextInputAction but I want to receive it after user pressed a button. (with ButtonAction)
I'm using the link_shared events to unfurl links in my workspace, trying to generate a template that is as close to Slack's unfurling template as possible, but I have several issues -
Blocks have very large spacing between them, causing my 3 blocks to take a lot of space
I'm unable to have an image inlined with the text for the title, unless I'm using context, but this is causing the text to be very small.
Taking Slack's example of how link unfurling should look like and trying to mimic it with blocks should explain the differences. This is the blocks message, and here you can see the result as an image
So my main question is - does Slack use some internal blocks formatting not available in the API, or is it possible to achieve the same result?
Thanks a lot!
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":pager: *Slack*"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<https://slack.com/features|Features>*"
}
},
{
"type": "image",
"title": {
"type": "plain_text",
"text": "Slack is where work flows. It's where the people you need, the information you share, and the tool you use come together to get things done.",
"emoji": true
},
"image_url": "https://a.slack-edge.com/13f94ee/marketing/img/homepage/self-serve-campaign/unfurl/img-unfurl-ss-campaign.jpg",
"alt_text": "Slack"
}
]
}
That example is not using the Slack block unfurl - it's an example of how a generic link would be displayed using the page's meta tags to display some additional information, using the favicon image.
If you wanted to create something similar you could use use a markdown block and an image block (like this) - but the file size would be displayed on a new line rather than after the text.
It took a bit of playing around, but I realized Slack is actually using message attachments (the legacy version of message formatting) in order to generate their link unfurls.
For example, if you want to unfurl a GitHub repository link, this is the payload you should send, and it'll generate an almost identical unfurling to what Slack is generating (a small Added by {app-name} will be added to the footer) -
unfurls["https://github.com/slackapi/bolt-js/"] = {
author_name: "GitHub",
author_icon: "https://a.slack-edge.com/80588/img/unfurl_icons/github.png",
title: "GitHub - slackapi/bolt-js: A framework to build Slack apps using JavaScript",
title_link: "https://github.com/slackapi/bolt-js/",
text: "A framework to build Slack apps using JavaScript. Contribute to slackapi/bolt-js development by creating an account on GitHub.",
image_url: "https://opengraph.githubassets.com/3e06f7eee96f05a53cd4905af3b296dfe333be7a902bb3e6a095770e87fd17fe/slackapi/bolt-js"
}
I am new to Slack APP development, I am developing the app using Slack bolt python. In my app I have configured the slack interaction using the button click, on clicking the button I am calling the corresponding listener(identified by action_id mentioned in the button). In the listener I am getting the block_actions payload which contains all the state values of the event, but in addition to that I want to some arguments to the listener function. Is it possible in any way that we can send additional arguments to the listeners
#app.action("change_time_period")
def handle_change_time_period(ack, context, body, client, logger, message, say):
# want the arguments here such as passing email_id from post_data
def post_data(user_id, email_id):
client = WebClient(token=os.environ.get("SLACK_BOT_TOKEN"))
result = client.chat_postMessage(
channel=user_id,
blocks=[
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"emoji": True,
"text": "Change time period"
},
"style": "primary",
"value": "time_period",
"action_id": "change_time_period"
}
]
}
]
)
In the code above, I will be calling the post_data which will post the message containing the block kit, once the user clicks the button the handle_change_time_period will be called
Slack block kit buttons do not have a field where we can pass metadata to the interactivity handler. One workaround to achieve this would be to make use of the value field of the button element dict to dump a JSON with the required data. From the Slack API doc, the value field can hold a maximum of 2000 characters. Your value field can be something like
"value": json.dumps({"actual_value" : "time_period", "email" : "johndoe#abc.com"})
This can be optimized further by reducing the characters in keys. If the extra data you need to pass goes beyond the char limit, you might have to consider caching the data on the server and passing a cache key in the block which can then be used in handler to retrieve the actual data from the cache.
I'm building a modal that has several select inputs on it. The values entered get posted to my server when the user clicks the modal submit button. However, for one of the selects I need it to post to the server immediately when the user interacts with it - and from what I understand, inputs don't do this.
So, I'm using an "Actions" layout block for one of the static select elements. However, the select looks nothing like the equivilent input static select. It's smaller and doesn't fill the full width of the video. Is there any way to do this?
You can use an input staticSelect and set the dispatchAction to true
{
"dispatch_action": true,
"type": "input",
"element": {
"type": "plain_text_input",
"action_id": "plain_text_input-action"
},
"label": {
"type": "plain_text",
"text": "Label",
"emoji": true
}
}
this works for the staticSelect as well
I am new to Docusign api and I am trying to post values from my form into a template. To be honest, I am not sure if I even created the custom fields properly or if there is some special way to set them into the form other than just creating a text field with a name.
I have read through the docs and recipes and about a dozen or more stack posts.
I am using rails and my fields post just fine but it's my tabs that do not. I read somewhere that I am supposed to use tabs and not custom_fields. Not sure if that's totally correct but that's how I've interpreted it.
Here is my current code:
body: {
"emailSubject": "DocuSign API call - Request Signature - Boom",
"templateId": "e1d5bce1-9757-4ffe-881b-054aa9139f2f",
"templateRoles": [{
"email": "#{renter.email}",
"name": "#{renter.background.legal_name}",
"roleName": "Lessee"
},{
"email": "#{#manager.email}",
"name": "#{#manager.name}",
"roleName": "Lessor",
"tabs": {
"texttabs": [{
"tabLabel": "Rent",
"value": "#{#lease.rent}"
},{
"tabLabel": "Address",
"value": "987 apple lane"
}]
}
}],
"status": "sent"
}.to_json
baseUrl that I am sending to:
"https://demo.docusign.net/restapi/v2/accounts/my_id/envelopes"
In your texttabs section, you should be passing in the following parameters at a minimum per tab: tablabel & value.
tablabel is the name of the tab that you have defined on the template. So from what I can tell, you have a text box on your template called Address. So you should put "tablabel":"Address".
value is what you would like to pre-populate in the tab. Looks like you have that correct.
You do not want to use tabID as that is not a valid parameter in this flow. The API documentation details what parameters you can use: https://www.docusign.com/p/RESTAPIGuide/RESTAPIGuide.htm#REST%20API%20References/Tabs/Text%20Tab.htm?Highlight=data%20tab
I also see an extraneous parameter of "Rent" under templateRoles section. That value will be ignored since it is not a valid parameter.
Turns out the problem was not with the code but with the setup within docusign. Make sure that you are setting up your tabs correctly and if you want to replicate a field multiple times make sure that they all share the same exact name.