使用Python和Flask的Slack API入门

The slick hosted chat application Slack is all the rage this year. The tool’s adoption isn’t empty hype – it’s incredibly useful for communicating with and learning from fellow developers. For example, software developer communities such as DC Python, Dallas-Forth Worth Devs, and Denver Devs set up their own Slack channels.

精巧的托管聊天应用程序Slack今年风靡一时。 该工具的采用并非吹牛,它对于与其他开发人员进行交流和向他们学习非常有用。 例如, DC PythonDallas-Forth Worth DevsDenver Devs等软件开发人员社区建立了自己的Slack渠道。

However, Slack wouldn’t be that useful if it was just a glorified AOL Instant Messenger. It’s the programmatic access to retrieve and send messages with the Slack web application programming interface (API) where the power really kicks in.

但是,如果Slack只是美化的AOL Instant Messenger,那么它就不会有用。 这是使用Slack Web应用程序编程接口(API)检索和发送消息的编程访问方式,真正发挥了作用。

In this post, we’ll see how to work with Slack via the API and the official SlackClient Python helper library. We will grab an API access token and write some Python code to list, retrieve and send data through the API. Let’s dig in now!

在本文中,我们将看到如何通过API和官方的SlackClient Python帮助程序库使用Slack。 我们将获取一个API访问令牌,并编写一些Python代码以列出,检索和通过API发送数据。 让我们开始吧!

Slack Python Flask

This is a guest blog post by Matt Makai​, Developer Evangelist at Twilio and author of Full Stack Python.

这是特维尔(Twilio)开发人员传教士,《 全栈Python》的作者Matt Makai的客座博客文章。

我们需要的工具 (Tools We’ll Need)

Several tools will be used to run the code in this blog post, including:

本博客文章中将使用几种工具来运行代码,包括:

It’s also handy to have the Slack API docs open for reference. You can follow along by writing the code in this post or clone the companion GitHub repository with the finished project.

打开Slack API文档以供参考也很方便。 您可以通过在本文中编写代码来进行后续操作,也可以使用完成的项目克隆配套的GitHub存储库

Now that we know what tools we need to use, let’s begin by creating a new virtualenv to isolate our application dependencies from other Python projects you’re working on:

现在我们知道我们需要使用什么工具,让我们开始创建一个新的virtualenv ,将我们的应用程序依赖项与您正在处理的其他Python项目隔离开:

1
1
2
2

Activate the virtualenv:

激活virtualenv:

1
1

Depending on how your virtualenv and shell are set up, your prompt should now look something like this:

根据您的virtualenv和shell的设置方式,您的提示符现在应如下所示:

1
1

Keep the shell open for now as we get our Slack access established via the official slackclient API helper library built by Slack.

现在通过我们由Slack构建的官方slackclient API帮助程序库建立Slack访问,保持外壳打开状态。

There are also other fantastic Python helper libraries created by the community. For simplicity, we’re only going to install and use slackclient, but you can also try out libraries like slacker,

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值