简体   繁体   English

创建一个传入的Webhook,发布到松弛状态

[英]Create an incoming webhook that posts to slack

I am developing a bootstrap application and I would like to do the following: 我正在开发引导程序应用程序,我想执行以下操作:

when a form is submitted, I want an incoming webhook from Slack to post the contents of the form to a slack channel. 提交表单时,我希望从Slack传入的Webhook将表单的内容发布到Slack频道。

Because I am using bootstrap, how would I go about creating this? 因为我使用的是引导程序,我将如何创建它?

Would I use Javascript or Node.js? 我会使用Javascript还是Node.js?

There are different ways how to do that. 有多种方法可以做到这一点。

The standard approach is to use server based scripts. 标准方法是使用基于服务器的脚本。 Your form calls a script on submit. 您的表单会在提交时调用脚本。 In that script you read the form content on startup (eg input from GET request), build a Slack message out of it and send it to your incoming webhook on your Slack team. 在该脚本中,您将在启动时读取表单内容(例如,来自GET请求的输入),从中构建Slack消息,并将其发送到Slack团队中的传入Webhook That is most commonly done with PHP, but other server based script languages like Python, node.js should work just as well. 这通常是用PHP完成的,但是其他基于服务器的脚本语言(如Python,node.js)也应该可以正常工作。

Check out this article at W3School on how to read form data with PHP. 看看这篇文章在W3School关于如何使用PHP读取表单数据。

If you want to do it with Javascript you could attach your JS function to the submit event of your form, read the form content on submit, build a Slack message out of it and send it to your incoming webhook. 如果要使用Javascript进行操作,则可以将JS函数附加到表单的Submit事件,在Submit上阅读表单内容,从中构建Slack消息并将其发送到传入的Webhook。 I would use jQuery and AJAX for that, but it would also work with pure Javascript. 我将为此使用jQuery和AJAX,但它也可以与纯Javascript一起使用。

However, with Javascript you would have to expose the incoming webhook URL to the browser, which would potentially open your Slack team to SPAM. 但是,使用Javascript,您必须将传入的Webhook URL公开给浏览器,这可能会使Slack团队接触到SPAM。 So I would suggest to stick with a server based solution. 因此,我建议您坚持使用基于服务器的解决方案。

Bootstrap is a set of CSS and Javascript that helps you make good looking and responsive websites, but does not have anything to do with sending form content to a webhook on Slack. Bootstrap是一组CSS和Javascript,可帮助您制作美观且响应迅速的网站,但与将表单内容发送到Slack上的Webhook无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM