新手指南:dvwa_如何构建基本的Slackbot:新手指南

新手指南:dvwa

By Vishwa Shah

Vishwa Shah着

Update: code and tutorial updated on June 28 to reflect Slack API changes.

更新:代码和教程已于6月28日更新,以反映Slack API的更改

Slackbots:为什么要使用它们? (Slackbots: Why use them?)

Before we get into the tutorial part of this post, let’s take a look at why this can be a worthy project and tool.

在进入本文的教程部分之前,让我们看一下为什么这可以成为一个有价值的项目和工具。

Slack is an increasingly popular tool for team-wide communication. It’s grown to include plugins for other widely used project management tools, like JIRA, Google Drive, and the likes. Any slack user knows — the more you can do from within the conversation, the better.

Slack是用于团队范围通信的越来越流行的工具。 它已经成长为包括其他广泛使用的项目管理工具(例如JIRA,Google云端硬盘等)的插件。 任何闲散的用户都知道-您在对话中可以做的越多越好。

Common uses for a slackbot range from a simple notifier for when a task is complete (like a test build, or when your lunch is ready) to interactive, button-based bots that execute commands at the user’s will. You can build polling mechanisms, conversational bots, and more.

slackbot的常见用途包括从简单的通知程序完成任务(例如测试版本,或午餐准备就绪)到根据用户意愿执行命令的基于按钮的交互式bot。 您可以构建轮询机制,对话机器人等。

设置python编程环境 (Setting up a python programming environment)

If you’re a windows user and you haven’t used python before, you’ll need to install it. Linux/Mac users: Unix comes with python!

如果您是Windows用户,并且以前从未使用过python,则需要安装它。 Linux / Mac用户:Unix随附python!

Once installed, fire up your terminal and type python or python3 (if you have multiple installations) to make sure it works and is there.

安装完成后,启动您的终端并输入pythonpython3 (如果您有多个安装),以确保其正常工作并存在。

Also check to see you have a good text editor for code: sublime and atom are great choices.

还要检查一下,看看您有一个不错的代码文本编辑器: sublime和atom是不错的选择。

Optional: It might also be useful to work in a virtual environment — it’s good practice for when you have a lot of dependencies.

可选:在虚拟环境中工作可能也很有用-当您有很多依赖项时,这是一个好习惯。

pip install virtualenv
virtualenv tutorial
source tutorial/bin/activate

You should also fork the tutorial GitHub repo and clone to your local machine, as we’ll be using that code as a framework for this tutorial.

您还应该将教程GitHub存储库分叉并克隆到您的本地计算机上,因为我们将使用该代码作为本教程的框架。

To do this, go to the repo and click Fork on the top right. The forked repo should be <yourusername>/slackbot-tutorial. Hit the green Clone or download button on the right under the stats bar, and copy the url. Return to the terminal to clone the repository:

为此,请转到存储库 ,然后单击右上角的Fork 。 分叉的仓库应该是<yourusername> / slackbot-tutorial 。 点击统计信息栏下方右侧的绿色Clone or download按钮,然后复制网址。 返回终端以克隆存储库:

cd Desktop/
git clone https://github.com/yourusername/slackbot-tutorial.git
cd slackbot-tutorial/
sublime . (or open your text editor and open this directory)

松弛应用 (Slack Apps)

There are two ways to go about creating your slackbot: standalone bots, or Slack apps. Apps allow a wider range of functionality going forward, and is Slack’s recommended route for creating a bot user.

创建slackbot有两种方法:独立bot或Slack应用。 应用程序可以支持更广泛的功能,这是Slack创建机器人用户的推荐途径。

Go to https://api.slack.com/apps and hit Create New App on the top right. Give it a name and pick a workspace where you can create a channel to test your bot in. You can always reconfigure your bot for another workspace later, or even post it to the Slack App Directory.

转到https://api.slack.com/apps,然后点击右上角的Create New App 。 给它起个名字并选择一个工作区,您可以在其中创建一个通道来测试您的bot。以后,您始终可以为另一个工作区重新配置bot,甚至将其发布到Slack App Directory中。

I recommend making a #test channel in a workspace you create just for development purposes, or one that has relatively few users who wouldn’t mind you testing something out there.

我建议您在仅为开发目的而创建的工作空间中创建一个#test通道,或者在相对较少的用户不介意您在那里进行测试的工作空间中创建#test通道。

The first thing you’ll want to do is get the bot token. When you get to the above page, click Bots. Add some scopes; these determine what permissions your app’s bot user will have. To start, chat:write and im:write are probably enough.

您要做的第一件事就是获取机器人令牌。 当您转到上一页时,单击Bots。 添加一些范围; 这些决定了您的应用的机器人用户将拥有哪些权限。 首先, 聊天:写 im:写 可能就足够了。

Now, to actually get your tokens, you’ll want to go to OAuth & Permissions on the left sidebar.

现在,要实际获取令牌,您需要转到左侧边栏上的OAuth & Permissions

Here, you’ll be able to Install the App to the Workspace and generate the necessary tokens. As a rule of thumb, bot tokens start with xoxb-.

在这里,您将能够Install the App to the Workspace并生成必要的令牌。 根据经验, 机器人令牌xoxb-.

You’ll also want the signing secret, which is located under Basic Information > App Credentials.

您还将需要signing机密 ,该机密位于“基本信息”>“应用程序凭据”下。

扮演你的机器人 (Acting as your Bot)

Now you have the credentials necessary to make API calls and act as your bot. To test this out, fire up a terminal and run this (with the correct token and channel name):

现在,您具有进行API调用并充当机器人的必要凭据。 要对此进行测试,请启动一个终端并运行它(使用正确的令牌和通道名称):

curl -X POST \-H 'Authorization: Bearer xoxb-your-token' \-H 'Content-type: application/json;charset=utf-8' \--data '{"channel":"#test","text":"Hello, Slack!"}' \
https://slack.com/api/chat.postMessage

If you go to that channel in your slack workspace, you should now see a message from your bot! You just made an HTTP POST request — asked a server to post a message somewhere.

如果您在闲置的工作空间中转到该频道,现在应该会看到机器人发出的消息! 您刚刚发出了HTTP POST请求-要求服务器在某处发布消息。

对机器人编程 (Programming the Bot)

We want to do the above programatically. There are a few different ways you can set up a slackbot. I’ll cover the following:

我们要以编程方式执行上述操作。 设置slackbot的方式有几种。 我将介绍以下内容:

  • Triggered periodically (on a schedule) to say something

    定期触发(按计划)说些什么
  • /slash commands

    /斜杠命令

The second requires a server running, while the first does not.

第二个要求服务器运行,而第一个不需要。

预定讯息 (Scheduled Messages)

Let’s say you want to periodically send a message somewhere — maybe every Monday morning. Go to the text editor where you opened up slackbot-tutorial.

假设您想定期在某处发送消息-也许每个星期一早上。 转到打开slackbot-tutorial的文本编辑器。

You should see a file scheduled.py. Take a look: sendMessage is a function that fires off the API call to slack and posts a message. At the bottom, you’ll see the main method: what executes when you run the script. Here, you’ll see a few things to note:

您应该看到一个文件scheduled.py 。 看一下: sendMessage是一个函数,该函数会触发API调用以放松并发布消息。 在底部,您将看到主要方法:运行脚本时执行的方法。 在这里,您会看到一些注意事项:

  • SLACK_BOT_TOKEN is pulled from os.environ['SLACK_BOT_TOKEN'] — how? Run export SLACK_BOT_TOKEN="xoxb-your-token" in your terminal to set this variable.

    SLACK_BOT_TOKEN是从os.environ['SLACK_BOT_TOKEN'] -如何? 在终端中运行export SLACK_BOT_TOKEN="xoxb-your-token"来设置此变量。

  • a scheduler is used here, and there’s an infinite loop that checks for events on the scheduler. By default here, I’ve scheduled the sendMessage function to be called every minute.

    这里使用了调度程序,并且存在一个无限循环,用于检查调度程序上的事件。 默认情况下,我已安排sendMessage函数每分钟调用一次。

To test this out, go back to the terminal where you’re in the slackbot-tutorial directory and run

要进行测试,请返回到slackbot-tutorial目录中的终端并运行

export SLACK_BOT_TOKEN="xoxb-your-token"
python scheduled.py

You should see the log messages print. Make sure you’ve changed channel=#test in the code to your test channel name (if different) and added your bot (in the slack channel, type /invite @botname. Let it run for a couple minutes and watch the messages show up on Slack!

您应该看到日志消息打印。 确保已将代码中的channel=#test更改为测试频道名称(如果有),并添加了您的机器人(在松弛频道中,键入/invite @botname 。让它运行几分钟,然后观看显示的消息)靠松弛!

This is, of course, a super basic implementation of a scheduled message sender — you can actually do this just with slackbot /remind #test “Hello, Slack!” every Monday at 9am.

当然,这是预定消息发送者的超基本实现-您实际上可以仅使用slackbot /remind #test “Hello, Slack!” every Monday at 9am /remind #test “Hello, Slack!” every Monday at 9am

The true power here is that you can substitute in any function for sendMessage, leveraging the power of interfacing with external services through APIs, doing math, etc and then constructing a message to post.

真正的强大之处在于,您可以用sendMessage替代任何功能,利用API通过与外部服务接口,进行数学运算等功能来构造要发布的消息。

斜杠命令 (Slash Commands)

This one requires a little more setup — go back to your app settings > Slash Commands. Create a new slash command: for example, /test. For the request URL, you’ll need to either deploy this web server (I use Heroku), or run a local ngrok instance to test it. The latter will run it locally, and is best for testing. You can brew install ngrok or get it from here.

这需要更多的设置-返回您的应用设置 > Slash命令。 创建一个新的斜杠命令:例如/test 。 对于请求URL,您将需要部署此Web服务器(我使用Heroku),或运行本地ngrok实例对其进行测试。 后者将在本地运行,最适合测试。 您可以brew install ngrok或从此处获取它。

In the starter code repo, look for slashCommand.py to start understanding this method. To start the server, run python server.py. The Request URL to put in Slack will be given by your ngrok instance and the @app.route in your code — it would be something like http://a1234b5cde6f.ngrok.io/slack/test (the bold part comes from the route defined in the code). You should be able to test the slash commands in your Slack workspace. From the tutorial code, try /test.

在入门代码存储库中,查找slashCommand.py以开始了解此方法。 要启动服务器,请运行python server.py 。 放入Slack的请求URL将由您的ngrok实例和代码中的@app.route提供-类似于http://a1234b5cde6f.ngrok.io / slack / test (粗体部分来自路由在代码中定义)。 您应该能够在Slack工作区中测试斜杠命令。 在教程代码中,尝试/test

向前进 (Moving Forward)

Now you have a very basic slackbot that either operates on a command or runs every so often. Be creative with how you use it! Think about what else you can link this skeleton to to make it more useful.

现在,您有了一个非常基本的slackbot,它可以在命令上运行,也可以经常运行。 发挥您的创造力! 考虑一下您还可以链接此框架以使其更有用。

您的漫游器可能会做出其他React (Other ways your bot might respond)

  1. Actions/responses could be triggered by mentions or certain phrases. This requires running a server and listening the messages somewhere.

    动作/响应可能由提及或某些短语触发。 这需要运行服务器并在某处侦听消息。
  2. You bot could be conversational, and might contribute to threads. Check out some NLP to get started on having intelligible conversation! Word2Vec + TensorFlow or Keras might be a place to start. DialogFlow is also great.

    您的漫游器可能是对话式的,并且可能有助于线程。 查看一些NLP,开始进行可理解的对话! Word2Vec + TensorFlow或Keras可能是一个起点。 DialogFlow也很棒。
  3. Link it up with some other APIs. Maybe you want to be able to interact with a Google Sheet and run some calculations. You might want to send other users a message based on some actions. Integrate buttons. Perhaps you want to trigger messages based on something else.

    将其与其他一些API链接起来。 也许您希望能够与Google表格进行交互并运行一些计算。 您可能希望根据某些操作向其他用户发送消息。 集成按钮 。 也许您想基于其他内容触发消息。

翻译自: https://www.freecodecamp.org/news/how-to-build-a-basic-slackbot-a-beginners-guide-6b40507db5c5/

新手指南:dvwa

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/392484.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java 加载class文件路径_动手实现MVC: 1. Java 扫描并加载包路径下class文件

背景用过spring框架之后&#xff0c;有个指定扫描包路径&#xff0c;然后自动实例化一些bean&#xff0c;这个过程还是比较有意思的&#xff0c;抽象一下&#xff0c;即下面三个点如何扫描包路径下所有的class文件如何扫描jar包中对应包路径下所有的class文件如何加载class文件…

leetcode 738. 单调递增的数字(贪心算法)

给定一个非负整数 N&#xff0c;找出小于或等于 N 的最大的整数&#xff0c;同时这个整数需要满足其各个位数上的数字是单调递增。 &#xff08;当且仅当每个相邻位数上的数字 x 和 y 满足 x < y 时&#xff0c;我们称这个整数是单调递增的。&#xff09; 示例 1: 输入: …

python+[:]+切片_我从C ++到Python的方式:概念上的改变

python[:]切片by asya f由asya f 我从C 到Python的方式&#xff1a;概念上的改变 (How I went from C to Python: a conceptual change) 介绍 (Introduction) People say that coding in Python is so easy that even a 6 year old can do it. This was the thought that I ha…

深度学习 免费课程_2020年排名前三的免费深度学习课程

深度学习 免费课程&#xff03;1 Fastai面向程序员的实用深度学习2020 (#1 Fastai Practical Deep Learning for Coders 2020) On 21 of August 2020, fastai released the new version of the fastai library and of their Deep Learning course!2020年8月21日&#xff0c;fas…

mysql复制主从集群搭建

近期搭了个主从复制。中间出了点小问题&#xff0c;排查搞定&#xff0c;记录下来1环境&#xff1a;虚拟机&#xff1a;OS:centos6.5Linux host2 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/LinuxserverIP192.168.18.66192.168.18.6…

java jolt tuxedo_java通过jolt调用tuxedo服务.xls

java通过jolt调用tuxedo服务.xls还剩20页未读&#xff0c;继续阅读下载文档到电脑&#xff0c;马上远离加班熬夜&#xff01;亲&#xff0c;喜欢就下载吧&#xff0c;价低环保&#xff01;内容要点&#xff1a;?private bea.jolt.pool.servlet.ServletSessionPoolManager bool…

你的周末时光是什么样的?

周末是一个特殊的假日&#xff0c;隔三差五就会有&#xff0c;来的容易去得也容易&#xff0c;即便如此&#xff0c;我们还是应该好好珍惜&#xff0c;周末可以做的事太多了&#xff0c;既可以用来减压&#xff0c;也可以为下一周的学习和工作充电&#xff0c;不管做什么&#…

leetcode 290. 单词规律(hash)

给定一种规律 pattern 和一个字符串 str &#xff0c;判断 str 是否遵循相同的规律。 这里的 遵循 指完全匹配&#xff0c;例如&#xff0c; pattern 里的每个字母和字符串 str 中的每个非空单词之间存在着双向连接的对应规律。 示例1: 输入: pattern “abba”, str “dog…

2019年微博用户画像_2019年您需要了解的有关用户的信息

2019年微博用户画像by Yisroel Yakovson通过伊斯洛尔雅科夫森 2019年您需要了解的有关用户的信息 (What You Need to Know About Your Users in 2019) Users have changed a lot in the last few years. We programmers may have a culture gap to overcome in this area. If …

使用lt;jsp:includegt;,不想写死URL,动态生成URL的解决的方法

JSP中文件包括有2种方式&#xff0c;静态包括和动态包括。静态包括使用<% include file"" %>。动态包括使用<jsp:include page"" />。本文不打算介绍这2种方式的差别和使用场景&#xff0c;主要关注page和file属性的路径问题。 假设事先知道被…

java udp ip端口 设置_UDP端口扫描Java只找到1个开放的UDP端口

我对端口扫描有一个分歧.我在Java中扫描一些IP地址的UDP端口.在我的程序中(假设一切正常)我只能找到一个开放的UDP端口.在另一方面端口扫描“nmap”我得到4个开放的UDP端口.有人可以告诉我为什么我不能通过Java代码找到多个端口&#xff1f;顺便说一句,我可以在我的代码中找到真…

pandas之Seris和DataFrame

pandas是一个强大的python工具包&#xff0c;提供了大量处理数据的函数和方法&#xff0c;用于处理数据和分析数据。 使用pandas之前需要先安装pandas包&#xff0c;并通过import pandas as pd导入。 一、系列Series Seris为带标签的一维数组&#xff0c;标签即为索引。 1.Seri…

机器学习:分类_机器学习基础:K最近邻居分类

机器学习:分类In the previous stories, I had given an explanation of the program for implementation of various Regression models. Also, I had described the implementation of the Logistic Regression model. In this article, we shall see the algorithm of the K…

leetcode 714. 买卖股票的最佳时机含手续费(dp)

给定一个整数数组 prices&#xff0c;其中第 i 个元素代表了第 i 天的股票价格 &#xff1b;非负整数 fee 代表了交易股票的手续费用。 你可以无限次地完成交易&#xff0c;但是你每笔交易都需要付手续费。如果你已经购买了一个股票&#xff0c;在卖出它之前你就不能再继续购买…

如何在Angular Material中制作自定义主题

by Charlee Li通过李李 如何在Angular Material中制作自定义主题 (How to make a custom theme in Angular Material) Angular Material is a great library that implements Material Design for Angular 2. The official document is sufficient regarding the component us…

最感叹的莫过于一见如故,最悲伤的莫过于再见陌路。最深的孤独,是你明知道自己的渴望,却得对它装聋作哑。最美的你不是生如夏花,而是在时间的长河里,波澜不惊。...

最感叹的莫过于一见如故&#xff0c;最悲伤的莫过于再见陌路。最深的孤独&#xff0c;是你明知道自己的渴望&#xff0c;却得对它装聋作哑。最美的你不是生如夏花&#xff0c;而是在时间的长河里&#xff0c;波澜不惊。转载于:https://www.cnblogs.com/dj258/p/7003890.html

java vimrc_.vimrc技巧

-------------------------------------------------------------------" 设置字符编码。参考&#xff1a;http://www.rainux.org/blog/index.php/2005/10/20/106" encoding: Vim 内部使用的字符编码方式&#xff0c;包括 Vim 的buffer (缓冲区)、菜单文" 本、消…

将PDF和Gutenberg文档格式转换为文本:生产中的自然语言处理

Estimates state that 70%–85% of the world’s data is text (unstructured data). Most of the English and EU business data formats as byte text, MS Word, or Adobe PDF. [1]据估计&#xff0c;全球数据的70&#xff05;–85&#xff05;是文本(非结构化数据)。 大多数…

Go_笔试题记录-指针与值类型实现接口的区别

1、如果Add函数的调用代码为&#xff1a; func main() {var a Integer 1var b Integer 2var i interface{} &asum : i.(*Integer).Add(b)fmt.Println(sum) } 则Add函数定义正确的是&#xff08;&#xff09; A.type Integer int func (a Integer) Add(b Integer) Intege…

leetcode 48. 旋转图像

解题思路 将数组从里到外分为若干层&#xff0c; 数组 [1,2,3], [4,5,6][7,8,9]的最外层即为 [1,2,3] [4 6][7,8,9] &#xff0c;将一层分为4条边&#xff0c;如741 123&#xff0c;将741放到123的位置&#xff0c;123放到369的位置&#xff0c;如此类推&#xff08;但是放置的…