Identify which button in message was clicked - slack

I'm sending messages with Block elements(buttons) to users using Slack API (python-slackclient). Different users can get number of these and can click the buttons with a delay obviously, for example the next day.
I need to identify which button in which message was clicked.
After checking the documentation on Slack API pages it looks like action_id is the way to go as I can specify it in my request and assign it a unique value. I shall get the action_id back in response coming to my endpoint once user clicks one of the buttons which will allow me to match it with sent message.
Is this the correct way to achieve it? Are you aware any better way to implement this?

You can use an action_id on your button in order to tie your button to a response action.
So if you have several buttons that should all trigger the same action, but you'd still need to know which of those buttons was clicked, maybe you could give them all the same action_id (so you can link them to the same action), but specify unique button values.

You need to make sure your action_ids are unique, BUT you can receive a message or an action using RegEx and thus still point them all to the same handler.
For example, this action handler receives all button presses where the action_id starts with "hello"
app.action(/^hello.*/, async ({ body, ack, say }: any) => {
await ack();
await say(`<#${body.user.id}> clicked the button`);
});

Related

Inline Keyboard with pager that spawns more menus

I try to create following logic:
User start conversation with command /display-playlists
Bot replies with a text for first batch of playlists (or any data) from database. For example first batch is 10 rows from database. Inline keyboard that comes with this message contains buttons for each of those rows + pager button like 'next' and 'previous', for next and previous batches (i already have this implemented, the problem is in the next step)
When user clicks on a button, that is "attached" to the row, bot should reply with a message for only this row, with inline keyboard, having options, that could be applied to this row.
So user calls the conversation to show playlists, chooses one of them, then chooses action for it from bots reply.
How it looks right now
It looks the way I want it to look like. The problem is that the third step is still a part of the initial conversation, so when i click on actions (show or delete) it goes to the entry point of inner conversation, so it just duplicates the message with options.
Conversation Handler for it:
ConversationHandler(
entry_points=[CommandHandler(name, display_playlists)],
states={
0: [
ConversationHandler(
entry_points=[
CallbackQueryHandler(pager, pattern=callback_utils.is_pager_action),
CallbackQueryHandler(action)
],
states={
0: [CallbackQueryHandler(apply)]
},
per_message=True,
fallbacks=[]
),
]
},
fallbacks=[],
allow_reentry=True
)
'pager' is a method for switching through batches (returns 0), 'action' is a method that displays single row keyboard for actions (returns 0), 'apply' is what is supposed to apply chosen action, but it is not implemented yet, as i try to resolve the problem in this post.
As you can see i did put "per_message" so i hoped each message with actions to be in its own conversation, so i could choose as many playlists as i want, and then click on their actions, without then interrupting each other. My guess is that i need to somehow catch clicks on actions through a completly separate CallbackQueryHandler, but i have no idea how to implement it, as there is almost no examples on how to use "per_message" in such manner.
I know that handler right now looks scuffed, i'm just experimenting, trying to make it work, so i guess you can just ignore it.
I'm using python-telegram-bot==13.12

How to tell which page a user was on when they fired the first of an event type in Google Analytics

I want to see what page on the site my users were on when they fired the first event action: add to cart, effectively starting their shopping journey within that session. I'm in Google Analytics, but completely stumped how to combine the pageviews and event action to pinpoint that this was the page the user was on the first time the user fired that event in their session (assuming Unique Event could be a metric used?).
Would love some ideas and help! Thank you!!
From the Events report you can't deduce when a user clicked for the first time on an element. The data is aggregated.
You could do it for example by sending a custom dimension at the time of the click on your element and assigning a cookie that checks if that information has already been sent to Analytics. If the cookie exists, don't send that dimension anymore.
It is not a 100% reliable method but it allows you to get the information you want for the future.

NGXS ofActionSuccessful

I have an angular component that subscribes to ofActionSuccessful. This action is dispatched as the user clicks on a button on the page. It is possible that the user may click on this button multiple times resulting in multiple dispatch events for this action
this.actions$.pipe(ofActionSuccessful(UpdateCommunicationPreferences)).subscribe(() => {
console.log('Action Successful');
});
this.store.dispatch(
new UpdateCommunicationPreferences(this.communicationPreferenceForm.value)
);
The issue that I am running into is ofSuccessful is triggered in an accumulated manner. In other words, the first time the user clicks on the button, the "Action Successful" is printed once. Second time the user clicks on the button, it is printed twice and so forth.
Can anyone help if there is a way to not get duplicate ofSuccessful events for the past actions?
Appreciate any insight.
This package was developed with your issue in mind:
https://www.npmjs.com/package/#ngxs-labs/actions-executing
#Select(actionsExecuting([UpdateCommunicationPreference])) myActionIsExecuting$: Observable;
you can use myActionIsExecuting$ in your template with async pipe. you can also simply subscribe to myActionIsExecuting to familiarize yourself with what is returned. null will be returned when all instances of that particular action are finished.
I hope that helps!
Take a look this: https://www.ngxs.io/advanced/cancellation
Extracted from the link: "If you have an async action, you may want to cancel a previous Observable if the action has been dispatched again. This is useful for canceling previous requests like in a typeahead."
Alternatively, you can consider a pattern that disables the UI when the button is clicked (e.g. via 'in progress' dialog) before triggering the action dispatch. When the action is done processing, close the dialog.
Hope this helps.

How to add RSVP button options in MailChimp template

I've created a party invitation template in MailChimp with an RSVP section within the body of the email that contains 3 buttons:
yes
maybe
no
I have also added a custom text field on the list called "RSVP".
Is there a way I can automate the user click event to automatically update the profile and target this field?
I realize I can add the |UPDATE_PROFILE| merge tag and send the user to a custom form where they choose their RSVP option, but ideally i want to bypass the form and handle the response using the buttons in the email body ONLY.
Is this possible?
Yes, this is possible, mostly. You can do most of what you want with survey tags. The result won't be put in your custom text field in your list called "RSVP", but you will still be able to make segments of your list based on who clicked a particular response, as described below.
Anywhere in your email, in a text portion, include the following:
*|SURVEY: 1. yes|*
*|SURVEY: 2. maybe|*
*|SURVEY: 3. no|*
When the recipient gets the email, they will see three links:
1. yes
2. maybe
3. no
These links will take them to a survey landing page. (You can edit this: in your lists page, click the drop down to the right of the stats button, then choose Signup Forms, and then choose Form Builder, then in the drop down choose Survey Landing Page)
After you send out the email, and some people have clicked some of your yes/maybe/no links, it's time to see the results.
Click on Campaigns at the top of mailchimp, then the View Report button to the right of the email you sent. Scroll down and you will see a box called Poll Information, and in this there is a link to View poll results. There you can see who clicked on which link.
You can also make a list segment based on Poll/Survey Activity, which lets you do things like see who all didn't pick any of your RSVP options, who did, and who clicked which one.

Can I cancel a controller request half way in ASP MVC?

Am very new to ASP MVC
I have a list of menu options that the user can choose. Each menu selection triggers one controller as per MVC architecture .
But unfortunately some of these controllers take some time for execution to make a visible change. Because the large data needs to be binded to a grid.So all that time browser hangs(shows loading).
The worst case occurs if user selects an option which could be easily loaded, after a time consuming menu option.
Can someone help on how to dismiss one controller action request if another comes in?
Right now its the summation of all user selected actions
Eg: If user selects Menu1 and after that Menu2 . And my Menu1 controller action is taking some time to execute. By that time User clicks Menu2 which is easily loaded if clicked for first time. But since Menu2 is clicked user has to wait a long.
This is a bit old but I will attempt to answer anyway since I ran into this problem recently. If you are using MVC 5, the other requests can be cancelled for you. The trick is to use async controller actions and to add a CancellationToken parameter.
public async Task<ActionResult> MyReallySlowReport(CancellationToken cancellationToken)
{
List<ReportItem> items;
using (ApplicationDbContext context = new ApplicationDbContext())
{
items = await context.ReportItems.ToListAsync(cancellationToken);
}
return View(items);
}
When the user navigates to another page, the request is cancelled. MVC will signal to the cancellation token that the request has been cancelled. As long as you also pass the cancellation token to the async data access method like I did above, the query will be cancelled and the server will stop working on the request immediately.
I have put together a full explanation here: http://www.davepaquette.com/archive/2015/07/19/cancelling-long-running-queries-in-asp-net-mvc-and-web-api.aspx

Resources