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

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!

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

Similar templates