Project Icon

slack-machine

简单强大的ChatOps框架

Slack Machine是一个功能丰富的Slack bot开发框架。它基于Slack Events API和Socket Mode,提供直观的插件系统,支持快速构建和代码模块化。框架具备多种交互功能,如响应正则表达式、处理斜杠命令和发送线程消息。此外,它还提供持久化存储和事件调度等高级特性,有助于将Slack工作区打造成高效的ChatOps平台。

Slack Machine

Join the chat at Slack image image image CI Status image

Slack Machine is a simple, yet powerful and extendable Slack bot framework. More than just a bot, Slack Machine is a framework that helps you develop your Slack workspace into a ChatOps powerhouse. Slack Machine is built with an intuitive plugin system that lets you build bots quickly, but also allows for easy code organization. A plugin can look as simple as this:

from machine.plugins.base import MachineBasePlugin
from machine.plugins.message import Message
from machine.plugins.decorators import respond_to


class DeploymentPlugin(MachineBasePlugin):
    """Deployments"""

    @respond_to(r"deploy (?P<application>\w+) to (?P<environment>\w+)")
    async def deploy(self, msg: Message, application, environment):
        """deploy <application> <environment>: deploy application to target environment"""
        await msg.say(f"Deploying {application} to {environment}")

Breaking Changes

Plugin initialization is now async (v0.35.0)

The optional initialization method plugins can implement, which is run once when the plugin is loaded, should be an async method starting the upcoming v0.35.0. The reason for this is that this allows plugins to interact with Slack through the Slack Machine's plugin API - most of which methods are async.

Simply prefix your init() methods with async.

Dropped support for Python 3.7 (v0.34.0)

As of v0.34.0, support for Python 3.7 has been dropped. Python 3.7 has reached end-of-life on 2023-06-27.

AsyncIO (v0.30.0)

As of v0.30.0 Slack Machine dropped support for the old backend based on the RTM API. As such, Slack Machine is now fully based on AsyncIO. This means plugins written before the rewrite to asyncio aren't supported anymore. See here for a migration guide to get your old plugins working with the new version of Slack Machine.

It's really easy!

Features

  • Get started with mininal configuration
  • Built on top of the Slack Events API for smoothly responding to events in semi real-time. Uses Socket Mode so your bot doesn't need to be exposed to the internet!
  • Support for rich interactions using the Slack Web API
  • High-level API for maximum convenience when building plugins
  • Low-level API for maximum flexibility
  • Built on top of AsyncIO to ensure good performance by handling communication with Slack concurrently

Plugin API features:

  • Listen and respond to any regular expression
  • Respond to Slash Commands
  • Capture parts of messages to use as variables in your functions
  • Respond to messages in channels, groups and direct message conversations
  • Respond with reactions
  • Respond in threads
  • Respond with ephemeral messages
  • Send DMs to any user
  • Support for blocks
  • Support for message attachments [Legacy 🏚]
  • Support for interactive elements
  • Listen and respond to any Slack event supported by the Events API
  • Store and retrieve any kind of data in persistent storage (currently Redis, DynamoDB, SQLite and in-memory storage are supported)
  • Schedule actions and messages
  • Emit and listen for events
  • Help texts for Plugins

Coming Soon

  • Support for modals
  • Support for shortcuts
  • ... and much more

Installation

You can install Slack Machine using pip:

$ pip install slack-machine

or add it to your Poetry project:

poetry add slack-machine

It is strongly recommended that you install slack-machine inside a virtual environment!

Usage

  1. Create a directory for your Slack Machine bot: mkdir my-slack-bot && cd my-slack-bot

  2. Add a local_settings.py file to your bot directory: touch local_settings.py

  3. Create a new app in Slack: https://api.slack.com/apps

  4. Choose to create an app from an App manifest

  5. Copy/paste the following manifest: manifest.yaml

  6. Add the Slack App and Bot tokens to your local_settings.py like this:

    SLACK_APP_TOKEN = "xapp-my-app-token"
    SLACK_BOT_TOKEN = "xoxb-my-bot-token"
    
  7. Start the bot with slack-machine

  8. ...

  9. Profit!

Documentation

You can find the documentation for Slack Machine here: https://dondebonair.github.io/slack-machine/

Go read it to learn how to properly configure Slack Machine, write plugins, and more!

项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

SubCat字幕猫

SubCat字幕猫APP是一款创新的视频播放器,它将改变您观看视频的方式!SubCat结合了先进的人工智能技术,为您提供即时视频字幕翻译,无论是本地视频还是网络流媒体,让您轻松享受各种语言的内容。

Project Cover

美间AI

美间AI创意设计平台,利用前沿AI技术,为设计师和营销人员提供一站式设计解决方案。从智能海报到3D效果图,再到文案生成,美间让创意设计更简单、更高效。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

Project Cover

天工AI音乐

天工AI音乐平台支持音乐创作,特别是在国风音乐领域。该平台适合新手DJ和音乐爱好者使用,帮助他们启动音乐创作,增添生活乐趣,同时发现和分享新音乐。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号