Passing additional data to the action listeners along with the block_actions payload in Slack Bolt python - slack-api

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.

Related

How to return friendly field names for zapier trigger (zapier developers)

I am working on a Zapier integration for an online form builder. Each unique form for our users has lots of long, auto-generated field names.
We have a trigger called “New form entries”, which polls our server for form entries, and comes back like this:
[
{
"id": "6209aee326baa600224d822c",
"email_907058157108782": "test#test.com",
"phone_589083232390193": "12345",
},
{
"id": "61fd629f19408200225e1893",
"email_907058157108782": "test#test2.com",
"phone_589083232390193": "54321",
},
]
However, this results in end users seeing these really long, gross field names in the Zapier interface:
My question: how do I get Zapier to display friendly labels to the user, whilst using the unique field IDs behind the scenes?
I’m thinking of returning something like the following (each object represents a form entry, , but I need to know how to actually use “friendlyFieldName” and “value” in Zapier!-
[
{
// the id for the entry
"id": "62179ec5ab9daa0022df7d1d",
// the id for the first field entry
"text_576692390099896": {
// a friendly name and value for zapier
"friendlyFieldName": "What is your favourite colour?",
"value": "Blue"
}
}
]
Thank you :)
You can define output fields labels in outputFields. Here are the reference document that you can follow: Output Fields

Issue passing in custom parameters to Twilio API

I am attempting to build out a process that will do the following:
New contact lands in my CRM (Podio)
The CRM is triggered to send a POST containing a custom parameter to Twilio which will then initiate a flow
The Twilio flow will call my cell and prompt me to connect to the new contact
Once I press 1, it will take the custom parameter (new contact's phone number) and connect
me to them.
So far, I have been able to get 1-3 with no problem.
However, according to the the API documentation from Twilio I should be able to pass a 3rd parameter in the JSON body of my HTTP request containing custom "Parameters". When I attempt this the parameters aren't showing in the Twilio studio logs and thus I am unable to connect the call to the new lead.
This is the JSON body I am sending over to my Twilio Flow's API
{
"To": "+1xxxxxxxxx1",
"From": "+1xxxxxxxxx2",
"Parameters": {
"name": "example name",
"prospectphone": "+1xxxxxxxxx3"
}
}
When I view the logs in Twilio this is what I received.
{
"contact": {
"channel": {
"address": "+1xxxxxxxxx2"
}
},
"trigger": {
"request": {
"from": "+1xxxxxxxxx2",
"to": "+1xxxxxxxxx1",
"parameters": {}
}
},
"widgets": {},
"flow": {
"flow_sid": "FW936f72c0eb8d3945d0d55c62465e37a8",
"data": {},
"channel": {
"address": "+1xxxxxxxxx2"
},
"sid": "FN955cdb12827f84c8af8fc9b5264e5a28"
}
}
I really can't figure out what I'm missing here? Has anyone run into this before? Is this something you can only do if you're using the SDK or does the additional parameter need to be passed in some other way?
It should be sent x-www-form-urlencoded.
From the documentation:
"Note: the JSON value must explicitly be passed as a string, not as a hash object. Depending on your particular HTTP library, you may need to add quotes or URL encode the JSON string."
Trigger a Twilio Studio Flow Execution via the REST API

Look a message's text from events api response

I'm using slacks events API and have setup a subscription to the reactions_added event. Now when a reaction is added to a message, slack will send me a post body with all the details of the dispatched event as described here.
The problem I'm having is that I want to get the details, specifically the text of the message that my users have reacted to so I can parse/store etc that specific message. I assumed the message would return with some type of UUID that I could then respond to the callback and get the text, however I'm find it difficult to get the specific message.
The only endpoint I see available is the channels.history, which doesn't seem to give me the granularity I'm looking for.
So the tl;dr is: How do I look up a via slacks API, a messages text sent from the events API? Give the information I have the event_ts, channel and message ts I thought would be enough. I'm using the ruby slack-api gem FWIW.
You can indeed use the method channels.history (https://api.slack.com/methods/channels.history) to retrieve message from a public channel . The reaction_added dispatched event includes the channel ID and timestamp of the original message (in the item) and the combination of channelId + timestamp should be unique.
Be careful that you use the correct timestamp though. You need to use item.ts not event_ts
Full example dispatched event from the docs:
{
"token": "z26uFbvR1xHJEdHE1OQiO6t8",
"team_id": "T061EG9RZ",
"api_app_id": "A0FFV41KK",
"event": {
"type": "reaction_added",
"user": "U061F1EUR",
"item": {
"type": "message",
"channel": "C061EG9SL",
"ts": "1464196127.000002"
},
"reaction": "slightly_smiling_face"
},
"event_ts": "1465244570.336841",
"type": "event_callback",
"authed_users": [
"U061F7AUR"
]}
So calling channels.history with these values set should work:
latest = item.ts value
oldest = item.ts value
inclusive = 1
channel = item.channel value
If you want to get messages from a private channel you need to use groups.history.
https://api.slack.com/methods/channels.history

Pre-setting values to Docusign template

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.

mandrill web-hooks open event "list of opens"

We are using mandrill, and we have webhooks configured to track open events.
But I am a bit confused about the JSON format what mandrill provides.
In of the formats, for open event, we have a key called "opens"
"opens": [
{
"ts": 1420010190,
"ip": "0.0.0.0",
"location": null,
"ua": "Linux/Linux/Gmail image proxy/Gmail image proxy"
},
{
"ts": 1420020155,
"ip": "0.0.0.0",
"location": null,
"ua": "Linux/Linux/Gmail image proxy/Gmail image proxy"
},
],
Are these objects unique ?
will they be duplicates? if so, do mandrill adds all the open list for every event we receive?
From the docs what i could understand is mandrill sends a webhook for every open, if it is, what are these list of opens in every event. which one would i consider.
It will be really helpfull, if someone explain the format.
Thanks in advance.
If you only want to record the individual opens, just use the data at the top level of the webhook event (ts, event, location, ip, for example). Everything under the msg key is data about the message that Mandrill knows when the webhook is created (so it's in addition to information about the individual open that triggered the webhook event). So the msg.opens key will be a list of all opens Mandrill knows about for the message at that time.

Resources