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)
Related
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 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.
In Apple iOS documentation it is mentioned that:
alert
string/dictionary
If this property is included, the system displays a standard alert or a banner, based on the user’s setting.
You can specify a string or a dictionary as the value of alert. If you specify a string, it becomes the message text of an alert with two buttons: Close and View. If the user taps View, the app launches. If you specify a dictionary, refer to Table 5-2 for descriptions of the keys of this dictionary.
title
string
A short string describing the purpose of the notification. Apple Watch displays this string as part of the notification interface. This string is displayed only briefly and should be crafted so that it can be understood quickly. This key was added in iOS 8.2.
body
string
The text of the alert message.
Now I want to set title for the push notification to be shown on iOS, I have sent the below payload:
{'data.project': {'ack': 0,
'c': {'id': 'SOME DATA'},
'ca': 1,
't': 'e/user',
'v': '1',
'vm': 2},
'msg': 'My message',
'title': 'My custom title'}
The push is sent but no title is set on the mobile device. Does pushd support it? What should I do?
Use this JSON Payload for sending push notification from backend. Hope this will help you. Here, "title" is the title of push notification and "body" is the text of alert message.
{
"registration_ids" : ["put_id_here"],
"notification" : {
"content_available" : true,
"body" : "this is body",
"title" : "this is title",
"sound" : "default",
"badge" : 1
}
}
I am using the typheous gem to create a new Event through the Google Calendar API (V3). The response returns 200 and a Calendar Event is created. My question, is there a way to always create the Event with a video-call attached as well?
response = Typhoeus::Request.new(
"https://www.googleapis.com/calendar/v3/calendars/calendarId/events",
method: :post,
body: {
start: {
dateTime: Time.parse(split_time_range[0])
},
end: {
dateTime: Time.parse(split_time_range[1])
},
attendees: [
{
email: "#{ENV["my_email"]}"
}
],
summary: "New Meeting"
}.to_json,
params: {access_token: session[:google_calendar_access_token], calendarId: "primary", sendNotifications: true},
headers: {"Content-Type": "application/json"}
).run
The Google Calendar event body does have a field called HangoutsLink
hangoutLink string An absolute link to the Google+ hangout associated with this event. Read-only.
As you can see this field is read only. I would try and send it when you are creating your event but i am not sure its something you can set with the API.
There is an issue logged for this Calendar API: Hangout not being added automatically to event when creating using the API. I have not been able to find the "automatically create a video call to a created event" setting which they speak of but its an old issue this may have been removed.
I have ASP.NET MVC (4) project which localization is supported by the framework. Should I change browser settings to another language, framework automatically picks up the right resource file.
However, because I am using knockoutjs I fall back to jQuery validation at those views. Unfortunately there's no automatic support for localization there.
My question is - what are the best practices and ways to customize and localize jQuery validation messages so they will be picked automatically together with all MVC resources?
Something that jQuery validation messages will behave in a similar manner to Data Annotations messages given resources and message Ids.
In particular -
How to I make jQuery pick up the message I want from the resources instead of its default "This field is required", so it will print something like "Please enter email" and
How can I make jQuery print the same customized message in another language automatically should I change browser language ?
Thank you in advance.
1) How to I make jQuery pick up the message I want from the resources instead of its default "This field is required", so it will print something like "Please enter email".
The following is called to over-ride messages at any time. The strings below can be replaced with variables.
jQuery.extend(jQuery.validator.messages, {
required: "This field is required.",
remote: "Please fix this field.",
email: "Please enter a valid email address.",
url: "Please enter a valid URL.",
date: "Please enter a valid date.",
dateISO: "Please enter a valid date (ISO).",
number: "Please enter a valid number.",
digits: "Please enter only digits.",
creditcard: "Please enter a valid credit card number.",
equalTo: "Please enter the same value again.",
accept: "Please enter a value with a valid extension.",
maxlength: jQuery.validator.format("Please enter no more than {0} characters."),
minlength: jQuery.validator.format("Please enter at least {0} characters."),
rangelength: jQuery.validator.format("Please enter a value between {0} and {1} characters long."),
range: jQuery.validator.format("Please enter a value between {0} and {1}."),
max: jQuery.validator.format("Please enter a value less than or equal to {0}."),
min: jQuery.validator.format("Please enter a value greater than or equal to {0}.")
});
Otherwise, you can get more specific when declaring your rules within .validate().
$(document).ready(function () {
$('#myform').validate({ // initialize the plugin
rules: {
field1: {
required: true,
minlength: 5
}
},
messages: {
field1: {
required: "custom message for field 1 required",
minlength: "custom message: {0} chars required"
}
}
});
});
DEMO: http://jsfiddle.net/XV3ZR/
To dynamically change any messages after the plugin is first initialized, requires an over-ride by using the rules('add') method.
$('#field1').rules('add', {
messages: {
required: "field 1 required",
minlength: "{0} chars required"
}
});
DEMO 2: http://jsfiddle.net/PJGgE/1/
2) How can I make jQuery print the same customized message in another language automatically should I change browser language ?
I'm not sure what you mean by "change browser language", but again, the methods in #1 above are the only ways, AFAIK. These are just strings and you'll have to translate them manually or via outside methods.
I think that you can give on the server to the client script file with localization depending client's browser settings (something like i18n)