slack 使用说明

by premprakashsingh

通过premprakashsingh

如何使用Node.js为Slack构建Meetupbot (How to build a Meetupbot for Slack using Node.js)

什么是松弛? (What is Slack?)

If you are new to Slack, it’s a great platform for team collaboration and instant messaging used in and out of organizations to help team communication and collaboration.

如果您不熟悉Slack ,那么它是团队协作和组织内外使用的即时消息传递的绝佳平台,可帮助团队进行沟通和协作。

I first used Slack for a study group. You can create different channels to separate messages and discussions. You can create private channels as well to keep messages private in a team.

我首先将Slack用于一个研究小组。 您可以创建不同的渠道来分隔消息和讨论。 您还可以创建私人渠道,以保持团队中的私人信息。

The best functionality is that it also allows integrations on it’s platform. And this is what makes it different than other messaging and collaboration platforms.

最好的功能是它还允许在其平台上进行集成。 这就是它与其他消息传递和协作平台不同的原因。

You can integrate Google Calendar, Twitter, Trello, and more. It also let’s you create custom applications like bots.

您可以集成Google日历,Twitter,Trello等。 它还使您可以创建自定义应用程序(例如bot)。

项目 (Project)

In this post, I will walk you through building a MeetupBot for Slack using Node.js. It will give you list of meetups going on near your location based on your interest.

在本文中,我将引导您使用Node.js为Slack构建MeetupBot 。 它将根据您的兴趣向您提供在您的位置附近进行的聚会的列表。

Feeling excited?

感觉非常激动?

It will use Slack’s slash commands. You can type /meetupbot from within Slack to call the MeetupBot and it will greet you along with the list of commands.

它将使用Slack的斜杠命令。 您可以在Slack中键入/ meetupbot来调用MeetupBot ,它将与命令列表一起打招呼。

I built this project as part of Chingu cohort with my 2 team members Zameer and Linus

我与2位团队成员Zameer和Linus一起在Chingu群组中建立了这个项目

You will need basic knowledge of Node.js and how APIs work. Let’s get started.

您将需要有关Node.js的基本知识以及API的工作原理。 让我们开始吧。

为Slack构建MeetupBot的步骤 (Steps for building MeetupBot for Slack)

第1步-项目设置 (Step 1 — Project Setup)

my repo URL : slack-meetup-botGlitch : glitch.comMeetup_api : meetup.com/meetup_api

我的回购网址: slack- meetup -bot 小故障: glitch.com Meetup_api: meetup.com/meetup_api

  • First fork my repository here.

    首先在这里派生我的存储库。

  • Then go to glitch.com and create a project and edit the project name to a shorter name.

    然后转到glitch.com并创建一个项目,然后将项目名称编辑为较短的名称。

  • Click on the Project Name > Advanced Options. Then click Import from GitHub. You first need to grant access of the GitHub repo to import your repositories into Glitch.

    点击项目名称 &g t; 先进的光学元件。 然后单击从Git Hub 导入 。 首先,您需要授予GitHub存储库访问权限,才能将您的存储库导入Glitch。

  • Go to Meetup Api here and click on API Key tab and save that as you will pass it with every request to Meetup API.

    转到此处的Meetup Api ,然后单击“ API密钥”选项卡,然后将其保存,因为您将在每次请求时将其传递给Meetup API。

  • In your Glitch project open .env file and set a variable SECRET as Your Meetup API Key as SECRET=<MeetupApiKey>

    在您的Glitch项目中,打开.env文件,并将变量SECRET设置为Meetup API密钥,设置为SECRET=<MeetupApiK ey>

  • Click on Show Live in Glitch and you will get your Glitch project URL.

    单击在Glitch中直播” ,您将获得Glitch项目URL。

第2步-创建一个Slack应用 (Step 2 — Create a Slack App)

  • Go to Slack apps and then click on Your Apps &gt; Create New App.

    转到Slack应用 ,然后单击您的应用 &g t; 创建新应用。

    It will show you following screen:

    它会显示以下屏幕:

Enter the App Name and select Development Slack Workspace and click on Create App. Now we need to do 3 things to see it working in our Slack workspace.

输入应用程序名称,然后选择Development Slack Workspace ,然后单击Create App 。 现在,我们需要做三件事,以使其在我们的Slack工作空间中工作。

On the next screen you will see your App Configuration page with following things:

在下一个屏幕上,您将看到“应用程序配置”页面,其中包含以下内容:

  1. Activate incoming webhooks.激活传入的Webhooks。
  2. Create Slash commands.创建斜杠命令。
  3. Install your app to your workspace.将应用程序安装到工作区。
  • Now click on Incoming Webhooks and activate it.

    现在,单击传入的Webhooks并将其激活。

    Incoming Webhooks allows you to post messages into Slack.

    传入的Webhooks允许您将消息发布到Slack。

  • Next thing click on Slash Command” and create one as /meetupbot. Command as /meetupbot, Request URL as <glitch-project-url>/meetupbot, and add a Short Description and a Usage Hint.

    接下来,单击“ Slash Command ”,然后将其创建为/ meetupbot 。 以/meetupbot作为命令,以<glitch-project-url>/mee tupbot 请求URL ,并添加简短描述 Usag e提示。

  • By activating Incoming Webhooks and creating Slash Commands you should have already got a green tick on Permissions.通过激活传入的Webhooks并创建斜杠命令,您应该在Permissions上已经有一个绿色的勾。
  • Now click on Install your app to your workspace and that will take you to next screen to confirm and authorize before installing. And now you are good to go.

    现在,单击“ 将应用程序安装到您的工作区” ,这将带您进入下一个屏幕,以在安装之前进行确认和授权。 现在,您很高兴。

第3步-在您的频道中对其进行测试 (Step 3 — Test it in your channel)

Open your Slack team channel and type /meetupbot and you should be able to see your commands popping up. Click Enter and you will see a greeting message from MeetupBot and a list of commands that you can use.

打开您的Slack团队频道并键入/ meetupbot ,您应该能够看到弹出的命令。 单击“ 输入” ,您将看到来自MeetupBot的问候消息以及可以使用的命令列表。

Since you have created only one slash command go to your App page and create 1 more commands as /meetupbot-show with Request URL as <glitch-project-url>/meetupbot-show (Follow step 2 — create Slack Command).

由于您仅创建了一个斜杠命令,请转到“应用程序”页面,并以/ meetupbot-show创建1个命令, 并将 请求URL作为<glitch-project-url>/meetupbo t-show创建(遵循步骤2-创建Slack命令)。

Now try this command, type /meetupbot-show San Francisco and JavaScript then hit Enter and you will see list of JavaScript meetups in San Francisco with details like Name of Event and Meetup Group, Date of Meetup, Status, Venue and Rsvp Count. Click on Event and it will take you to their Meetup Event page.

现在尝试此命令,键入/meetupbot-show San Francisco and JavaScript然后按Enter,您将看到San Francisco中JavaScript聚会的列表,其中包括事件名称和聚会组,聚会日期,状态,地点和Rsvp计数等详细信息。 单击事件,它将带您到他们的聚会会议页面。

So that’s it, Congratulations you have successfully created a MeetupBot for Slack using Node.js.

就是这样,恭喜您已经使用Node.js为Slack成功创建了MeetupBot。

让我们了解代码。 (Lets understand the code.)

We are using the Google Geocode API to get Latitude and Longitude from location/address parameter that is passed in the command. This latitude and longitude along with interest parameter is then passed to the Meetup API to get a list of meetups.

我们正在使用Google Geocode API从命令中传递的location / address参数获取纬度和经度。 然后,此纬度和经度以及兴趣参数将传递到Meetup API,以获取Meetup的列表。

Also we are using Express.js and JavaScript Promises, npm packages Moment.js for parsing dates and Request to make API calls.

另外,我们使用Express.js和JavaScript Promises,npm包Moment.js解析日期,并请求进行API调用。

What happens when you call /meetupbot ? It makes a Post request to glitch-project-url/meetupbot.

致电/meetupbot会发生什么? 它向glitch-project-url/meetupbot发出Post请求。

The request body contains user_name, text and other info. The reply object is the JSON response format for the Slack API.

请求主体包含user_nametext和其他信息。 回复对象是Slack API的JSON响应格式。

What happens when you call /meetupbot-show ? It makes a Post request to glitch-project-url/meetupbot. The request body contains the user_name, text (such as location and interest separated by “&”) and other info.

致电/meetupbot-show会发生什么? 它向glitch-project-url/meetupbot发出Post请求。 请求正文包含user_nametext (例如位置和兴趣,用“&”分隔)和其他信息。

We first make sure the location and interest parameters sent with the command are not blank.

我们首先确保随命令发送的location和interest参数不为空。

Then we pass location to getGeocode method which is a JavaScript Promise that make calls to Google Geocode API and returns Latitude and Longitude, which is then passed to getMeetupEvents Promise to get list of meetup by making a call to Meetup API.

然后,我们将位置传递给getGeocode方法,该方法是对Google Geocode API进行调用JavaScript Promise,并返回纬度和经度,然后将其传递给getMeetupEvents Promise,以通过对Meetup API进行调用来获取getMeetupEvents列表。

The Meetup API returns an array of meetup event objects and we iterate through this array to make an array of event objects in Slack response format and keep pushing it in the attachment array which we created in the start.

Meetup API返回一个Meetup事件对象数组,我们迭代该数组以Slack响应格式创建一个事件对象数组,并继续将其推入我们在开始时创建的attachment数组中。

And that reply with event attachments is then returned as response and is shown in your Slack.

然后,带有事件附件的答复将作为响应返回,并显示在您的Slack中。

This response will only be visible to you (the user who calls the bot ) and won’t disturb other members of channel.

该响应仅对您(调用bot的用户)可见,并且不会打扰频道的其他成员。

In the above code we have 2 Promises as follows:

在上面的代码中,我们有两个Promises,如下所示:

  • getGeoCode() — This take location as parameter and makes an API call to Google Geocode API with location as query string and returns latlong.

    getGeoCode() —以位置为参数,并以位置作为查询字符串对Google Geocode API进行API调用,并返回latlong

  • getMeetupEvents() — This takes location and interest as parameters and makes API call to Meetup API containing the API Key, Latitude, Longitude, text or interest and radius as query string parameters.

    getMeetupEvents() —这将位置和兴趣作为参数,并向Meetup API进行API调用,其中包含API密钥,纬度,经度,文本或兴趣和半径作为查询字符串参数。

The above code uses JavaScript Promise which is basically used to handle asynchronous operations. It allows you to write asynchronous code that is similar in style to synchronous code.

上面的代码使用了JavaScript Promise,它基本上用于处理异步操作。 它使您可以编写与同步代码风格相似的异步代码。

Also helps in avoiding nested callbacks by using chainable then. If you have nested callbacks in code then it looks like pyramid structure also known as “callback hell”.

通过使用chainable then还有助于避免嵌套回调。 如果您在代码中嵌套了回调,则它看起来像金字塔结构,也称为“回调地狱”。

官方MeetupBot (Official MeetupBot)

The official MeetupBot has one more command as /meetupbot-find to get list of meetup group in your location/area and also has Oauth code so that you can install it by clicking add to slack button.

官方的MeetupBot还有一个命令/ meetupbot-find来获取您所在的位置/区域中的metup组的列表,并且还具有Oauth代码,因此您可以通过单击添加到松弛按钮来安装它。

You can find it here MeetupBot landing page and MeetupBot github repo. Start using it now.

您可以在此处找到MeetupBot登陆页面和MeetupBot github存储库 。 现在就开始使用它。

Did you find this article useful? Write your comments below.

你觉得这篇文章有用吗? 在下面写下您的评论。

If you found this article helpful, do share with your friends and give this couple of claps.

如果您发现本文有帮助,请与您的朋友分享并给予一些鼓掌。

— Thank you :)

- 谢谢 :)

Originally posted here.

最初在这里发布。

翻译自: https://www.freecodecamp.org/news/how-to-build-a-meetupbot-for-slack-using-node-js-618725aa4c6e/

slack 使用说明

slack 使用说明_如何使用Node.js为Slack构建Meetupbot相关推荐

  1. node.js 组件_使用Node.js和TransloadIt构建用户头像组件

    node.js 组件 在本系列的第一部分中,我们介绍了TransloadIt -一种文件处理服务,专门处理图像,视频和音频. 如果您还没有阅读它,我建议您立即阅读,因为它涵盖了很多背景概念,您需要阅读 ...

  2. slack 使用说明_开发人员应使用的7个Slack集成

    slack 使用说明 如何使用集成和机器人自定义Slack来增强您的开发工作流程 毫无疑问,Slack正在逐渐成为现代办公通信的标准. 尽管您可能会说Slack从技术上讲与IRC没什么不同,但是精湛的 ...

  3. 使用Node.js和TransloadIt构建用户头像组件

    在本系列的第一部分中,我们介绍了TransloadIt -一种文件处理服务,专门处理图像,视频和音频. 如果您还没有阅读它,我建议您立即阅读,因为它涵盖了很多背景概念,您需要阅读这些概念才能继续阅读本 ...

  4. slack 使用说明_我如何使用Node和Botkit构建HR Slack Bot

    slack 使用说明 为什么要创建Slack Bot? (Why create a Slack Bot ?) I am an HR professional. More specifically I ...

  5. node.js使用手册_权威的Node.js手册

    node.js使用手册 Note: you can get a PDF, ePub, or Mobi version of this handbook for easier reference, or ...

  6. node.js 生成文件_如何使用Node.js在几秒钟内生成模拟数据

    node.js 生成文件 介绍 (Introduction) In most of the applications, you need to have some static JSON data w ...

  7. node aws 内存溢出_如何使用Node.js和AWS快速创建无服务器RESTful API

    node aws 内存溢出 by Mark Hopson 马克·霍普森(Mark Hopson) 如何使用Node.js和AWS快速创建无服务器RESTful API (How to quickly ...

  8. node开启子线程_多进程 amp; Node.js web 实现

    更好阅读体验: 多进程 & Node.js 实现 · 语雀​www.yuque.com 进程与线程 进程和线程的诞生要从多任务谈起,多任务是指操作系统可以在同一时间内运行多个应用程序,CPU ...

  9. 集群资源分配_分析下 Node.js 关于集群的那些事

    需要了解的基础概念 一个应用程序中,至少包含一个进程,一个进程至少包含一个线程. 进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位 线程(Thr ...

最新文章

  1. 雷博招聘|机器人(SLAM)、深度学习、机器视觉算法工程师等岗位
  2. python判断集合为空
  3. [云炬创业基础笔记]第六章商业模式测试8
  4. vue --- 使用字符串'api'跨域请求资源
  5. linux创建目录目录文件,Linux创建目录和文件管理教程
  6. python作业代码没有缩进严重吗_Python代码需要缩进吗
  7. Java中线程出现Exception in thread Thread-0 java.lang.IllegalMonitorStateException异常 解决方法...
  8. EndnoteX9下载并安装
  9. 根据Word模板动态生成PDF
  10. php根据手机号码获取归属地,PHP通过API获取手机号码归属地
  11. 【私有,不喜勿入】健康
  12. 4月24日云栖精选夜读:AI不可怕,就怕AI会画画——这里有一种你还不知道的‘图’灵测试…...
  13. Python出租车GPS数据的路网匹配(TransBigData+leuvenmapmatching)
  14. 计算广告概述【计算广告】
  15. 邬贺铨:商用一周年,5G成为中国数字经济的“新引擎”
  16. java科目二踩线原理,右倒车入库总踩线?是因为没有看到这些“秘诀”
  17. html怎么转换成ftl模板,FreeMarker入门+模板静态化+模板字符串静态化
  18. MySQL全量同步和增量同步-
  19. Docker-compose快速部署PostgreSQL
  20. android手机文件误删除恢复软件,被误删除的文件用安卓手机数据恢复软件怎么找回...

热门文章

  1. 使用preparedStatement执行sql语句 20210411094249744
  2. 字节流复制文件 java
  3. 01 能够使用Format实现格式化输出显示
  4. java 作业 老师与教员信息 类与对象
  5. 移动端相关 em rem px 区别和关联
  6. django-获取用户数据小结-编辑中
  7. linux-路径的切换-文件的增删拷-目录的增删拷
  8. redis中文显示问题
  9. 通过自定义消息调用主窗体的菜单项
  10. linux:shell:tree