新手指南: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.pswp.cn/news/392484.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392484.shtml
英文地址,請注明出處:http://en.pswp.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;但是放置的…