Slack Mention Poem Generator

Test this app for free
57
import os
import re
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
from abilities import llm_prompt

# Install the Slack app and get xoxb- token in advance
app = App(token=os.environ["SLACK_BOT_TOKEN"])

@app.command("/hello-socket-mode")
def hello_command(ack, body):
    user_id = body["user_id"]
    ack(f"Hi, <@{user_id}>!")

@app.event("app_mention")
def event_test(body, say, event):
    user_message = re.sub('<.*?>', '', body['event']['text']).strip()
    thread_ts = event['ts']
    if len(user_message) == 0:
        say("Sorry, I couldn't generate a joke as there was not enough text. Please provide more text.", thread_ts=thread_ts)
    else:
        say("Generating a miracle, please wait...", thread_ts=thread_ts)
        poem = llm_prompt(f"Write a joke about {user_message} in 150 words or less", model="gpt-4", temperature=0.8)
Get full code

Frequently Asked Questions

How can the Slack Mention Poem Generator benefit my business communication?

The Slack Mention Poem Generator can enhance your business communication by adding a creative and engaging element to your Slack workspace. It can help break the ice in team discussions, spark creativity, or simply provide a moment of levity during the workday. By generating poems based on user messages, it encourages more interactive and enjoyable communication among team members.

Can the Slack Mention Poem Generator be customized for specific business needs?

Absolutely! The Slack Mention Poem Generator is highly customizable. You can modify the prompt sent to the AI to generate content that aligns with your business needs. For example, instead of poems, you could generate product descriptions, marketing slogans, or even brief reports. Simply adjust the llm_prompt function call in the code to suit your specific requirements.

What are the potential use cases for the Slack Mention Poem Generator in a corporate setting?

The Slack Mention Poem Generator has several potential use cases in a corporate setting: - Team building: Use it to create fun, personalized poems for team members on special occasions. - Brainstorming sessions: Generate creative ideas based on keywords or themes. - Internal communications: Create engaging announcements or reminders in a poetic format. - Customer service: Generate unique, personalized responses for customer inquiries. - Training and onboarding: Create memorable, poem-based summaries of company policies or procedures.

How can I modify the Slack Mention Poem Generator to use a different AI model?

To use a different AI model with the Slack Mention Poem Generator, you'll need to modify the llm_prompt function in the abilities.py file. Here's an example of how you might change it to use a hypothetical "AlternateAI" model:

```python from alternate_ai import AlternateAI

def llm_prompt(prompt, model="alternate-gpt", temperature=0.7): ai = AlternateAI(model=model, temperature=temperature) response = ai.generate(prompt) return response.text ```

Remember to import and set up the new AI library according to its documentation.

Can I add more Slack commands to the Slack Mention Poem Generator?

Yes, you can easily add more Slack commands to the Slack Mention Poem Generator. Here's an example of how you might add a new command to generate a haiku:

```python @app.command("/generate-haiku") def generate_haiku(ack, body, say): ack() user_id = body["user_id"] topic = body["text"]

   say("Generating a haiku, please wait...")

   haiku = llm_prompt(f"Write a haiku about {topic}", model="gpt-4", temperature=0.8)

   say(f"Here's your haiku about {topic}, <@{user_id}>:\n\n{haiku}")

```

This new command allows users to type /generate-haiku [topic] in Slack to receive a custom haiku. Remember to add this new command in your Slack app settings for it to work.

Created: | Last Updated:

This app listens to mentions of our app on Slack, sends a loading message, and then responds with a poem generated by an AI in the same thread as a reply to the original mention. The poem is based on the message sent by the user. The app requires two environment variables: SLACK_BOT_TOKEN and SLACK_APP_TOKEN. These tokens are used to authenticate the app with Slack. To generate these tokens, you need to create a new app in your Slack workspace, add the bot scope, install the app in the workspace, enable Socket Mode for the app in the Slack API settings, and generate an App-Level token.

Introduction to the Slack Mention Poem Generator Template

Welcome to the Slack Mention Poem Generator template! This template allows you to create an app that listens for mentions on Slack and responds with a custom-generated poem based on the user's message. It's a fun and interactive way to engage with your team or community on Slack.

To get started, simply click Start with this Template on the Lazy platform. This will set up the template in your Lazy Builder interface, and you'll be ready to customize it to your liking.

Setting Environment Secrets

Before you can use this template, you'll need to set up two environment secrets:

  • SLACK_BOT_TOKEN
  • SLACK_APP_TOKEN

These tokens are essential for authenticating your app with Slack. Here's how to obtain and set them:

  1. Create a new app in your Slack workspace.
  2. Add the bot scope to your app.
  3. Install the app in your workspace.
  4. Enable Socket Mode for the app in the Slack API settings.
  5. Generate an App-Level token (SLACK_APP_TOKEN).
  6. Once you have the tokens, go to the Environment Secrets tab within the Lazy Builder.
  7. Enter the tokens as secrets with the names SLACK_BOT_TOKEN and SLACK_APP_TOKEN.

External Integrations

No external integrations are required for this template beyond setting up the Slack app and obtaining the necessary tokens as described above.

Using the Test Button

After setting up your environment secrets, you can use the Test button to deploy your app. The Lazy CLI will guide you through any additional user input that may be required. Once the app is running, you'll be able to interact with it directly in your Slack workspace.

When someone mentions your app in a Slack channel, the app will acknowledge the mention and then use the built-in 'abilities' module to generate a poem based on the message content. The poem will be posted as a reply in the same thread.

How to Use the Slack Mention Poem Generator

Once your app is deployed and running, here's how to use it:

  1. Mention your Slack app in a message by typing @your_app_name followed by a message.
  2. The app will post a loading message indicating that a poem is being generated.
  3. After a short wait, the app will reply in the same thread with a custom poem based on the text you provided.

Enjoy engaging with your Slack community in a creative and entertaining way with your very own AI-powered poem generator!

If you need further assistance or have any questions, please reach out to our customer support team. We're here to help you make the most of your Lazy experience!



Template Benefits

  1. Enhanced Team Communication: This Slack bot can foster creativity and engagement within teams by generating custom jokes based on user input, potentially improving morale and team bonding.

  2. Automated Content Creation: The template demonstrates how AI can be leveraged to automatically generate content, which could be adapted for various business needs such as marketing copy or customer service responses.

  3. Seamless Integration with Existing Tools: By integrating with Slack, a widely-used business communication platform, this template shows how AI capabilities can be easily incorporated into existing workflows without disrupting them.

  4. Scalable Customer Interaction: While this example generates jokes, the same principle could be applied to create chatbots for customer service or sales, providing quick, personalized responses at scale.

  5. Demonstration of AI Capabilities: This template serves as a tangible demonstration of how AI can be practically applied in business settings, potentially sparking ideas for other AI-driven innovations 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

Similar templates