Create a Custom Poll in Slack Account or Channel

Test this app for free
55
import os
import json
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler

# Initialize a Bolt for Python app
app = App(token=os.environ["SLACK_BOT_TOKEN"])

# Global dictionary to store poll votes
poll_votes = {}
# Global dictionary to store user votes
user_votes = {}

# Listen for a slash command invocation
@app.command("/poll")
def create_poll(ack, body, say):
    ack()
    channel_id = body["channel_id"]  # Capture the channel ID where the command was invoked
    trigger_id = body["trigger_id"]
    # Modal view to collect poll information
    app.client.views_open(
        trigger_id=trigger_id,
        view={
Get full code

Frequently Asked Questions

How can this Custom Poll app benefit team collaboration and decision-making in a business setting?

The Custom Poll app for Slack enhances team collaboration and decision-making by providing a quick and easy way to gather opinions and feedback. It allows team members to create polls directly within Slack channels, making it convenient for everyone to participate. The real-time updating of poll results promotes transparency and can help teams reach consensus faster. This tool is particularly useful for making group decisions, prioritizing tasks, or gathering input on various business matters without the need for lengthy meetings or email chains.

Can the Custom Poll app be used for employee engagement surveys?

Yes, the Custom Poll app can be an excellent tool for conducting quick employee engagement surveys. Its ease of use and integration with Slack make it ideal for frequent, lightweight surveys. For example, you could create weekly polls to gauge team morale, collect feedback on recent changes, or assess satisfaction with ongoing projects. The anonymity of votes encourages honest responses, while the real-time results allow management to quickly identify and address any issues. However, for more comprehensive or sensitive surveys, you may want to use dedicated survey tools that offer more advanced features and data protection.

How does the Custom Poll app ensure fair voting and prevent manipulation?

The Custom Poll app includes several features to ensure fair voting:

How can I modify the Custom Poll app to allow multiple votes per user?

To allow multiple votes per user, you would need to modify the handle_button_click function. Instead of replacing the user's previous vote, you would add each vote to a list. Here's an example of how you could modify the relevant part of the code:

```python @app.action("vote_button") def handle_button_click(ack, body, client): ack() user_id = body["user"]["id"] action_value = json.loads(body["actions"][0]["value"]) poll_id = action_value["poll_id"] voted_option = action_value["option"]

   # Initialize user's votes if not already present
   if user_id not in user_votes:
       user_votes[user_id] = {}
   if poll_id not in user_votes[user_id]:
       user_votes[user_id][poll_id] = []

   # Add the new vote
   user_votes[user_id][poll_id].append(voted_option)

   # Increment the vote count for the chosen option
   poll_votes[poll_id][voted_option] += 1

   # Update the poll message...

```

Remember to also update the update_poll_blocks function to reflect the new voting system.

How can I extend the Custom Poll app to include a time limit for polls?

To add a time limit to polls, you can use Python's threading module to schedule the closing of the poll. Here's an example of how you could modify the handle_submission function to include a time limit:

```python import threading

@app.view("poll_view") def handle_submission(ack, body, view, client): ack() # ... existing code ...

   # Add a field for poll duration in minutes
   duration = int(values["poll_duration"]["duration"]["value"])

   # Schedule poll closing
   threading.Timer(duration * 60, close_poll, args=[client, channel_id, poll_id]).start()

   # ... rest of existing code ...

def close_poll(client, channel_id, poll_id): # Update the poll message to show it's closed blocks = update_poll_blocks(poll_id) blocks.append({ "type": "section", "text": {"type": "mrkdwn", "text": "This poll is now closed."} })

   client.chat_update(
       channel=channel_id,
       ts=poll_votes[poll_id]["message_ts"],  # You'll need to store this when creating the poll
       text=f"Poll closed: {poll_id.split('-')[2]}",
       blocks=blocks
   )

```

This modification adds a timer that will automatically close the poll after the specified duration. You'll also need to add a new input field in the modal view to allow users to set the poll duration.

Created: | Last Updated:

This app allows users to create polls on Slack using the /poll command. It posts an interactive message with poll options in the channel where the command was invoked, captures users' responses, and updates the poll message to display the current anonymous results. Users can change their votes, and the app will update the poll results accordingly. The app requires SLACK_BOT_TOKEN and SLACK_APP_TOKEN for authentication and must be subscribed to interaction events to capture votes.

Introduction to the Custom Poll Creation Template for Slack

Welcome to the step-by-step guide on how to use the Custom Poll Creation Template on the Lazy platform. This template allows you to easily create and manage interactive polls within Slack channels. With this app, you can post polls, collect responses, and display real-time results, all through simple slash commands and button interactions. This guide will walk you through the process of setting up and deploying your custom poll app on Slack using Lazy.

Getting Started with the Template

To begin using this template, click on "Start with this Template" on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy, paste, or delete any code manually.

Initial Setup: Adding Environment Secrets

Before testing the app, you need to set up the necessary environment secrets. These are not the same as environment variables in your operating system; they are secrets that can be set in the Environment Secrets tab within the Lazy Builder.

You will need to set up the following environment secrets:

  • SLACK_BOT_TOKEN: This is the token for your Slack bot. You can obtain it by creating a new bot in your Slack app settings and assigning the necessary scopes.
  • SLACK_APP_TOKEN: This token is used for socket mode and can be generated in the Slack API settings under the "App-Level Tokens" section.

Make sure to acquire these tokens from your Slack app settings and add them as environment secrets in the Lazy Builder interface.

Test: Deploying the App

Once you have added the necessary environment secrets, you can deploy the app by pressing the "Test" button. This will begin the deployment process and launch the Lazy CLI. The Lazy platform handles all deployment aspects, so you don't need to worry about installing libraries or setting up your environment.

Using the App

After deploying the app, you can use the custom poll feature in your Slack workspace. Invoke the poll creation by typing the /poll command in any channel where the bot is present. A modal will appear, prompting you to enter the poll question and options. Once submitted, an interactive message with the poll options will be posted in the channel, and users can start voting.

Integrating the App

To integrate this app into your Slack workspace, you need to ensure that your Slack bot has the following scopes:

  • commands
  • chat:write
  • chat:write.public

Add these scopes in your Slack app settings under the OAuth \& Permissions section. After adding the scopes, reinstall the app to your workspace to apply the changes.

If your app uses additional features or requires further integration with Slack or other services, follow the specific instructions provided in the documentation or the code comments.

That's it! You've successfully set up and deployed a custom poll creation app in Slack using the Lazy platform. Enjoy engaging with your team through interactive polls!



Here are 5 key business benefits for this Slack poll creation template:

Template Benefits

  1. Enhanced Decision Making: Enables quick, democratic decision-making within teams by allowing easy creation and participation in polls, leading to more inclusive and data-driven choices.

  2. Improved Team Engagement: Encourages active participation from all team members, fostering a culture of collaboration and ensuring everyone's voice is heard on important matters.

  3. Efficient Feedback Collection: Streamlines the process of gathering opinions and feedback on various topics, saving time compared to traditional methods like email surveys or meetings.

  4. Real-time Insights: Provides instant, updated results as votes are cast, allowing for immediate action based on the most current data without waiting for a final tally.

  5. Increased Transparency: Promotes openness in decision-making processes by making poll results visible to all participants, which can boost trust and accountability within the organization.

Technologies

Streamline Slack Workflows with Lazy AI: Automate Notifications, API Integrations and More  Streamline Slack Workflows with Lazy AI: Automate Notifications, API Integrations and More