Slack斜杠命令 - 变量/参数

时间:2016-08-31 15:56:28

标签: slack-api slack

我正在将slackjenkins集成以使用slash命令,并希望了解slash命令是否variables

我想做的是这样的事情;

/this_word_should_be_in_the_url word

并且能够在word斜杠命令中使用URL来调用。

在他们的页面上,他们有类似/weather 94070

的内容

我是否可以访问94070,并以某种方式设置为网址的query参数。

这可能吗? 找不到任何相关的文档。

感谢。

1 个答案:

答案 0 :(得分:7)

Yes. You will have access to the word as per the example that you mentioned.

So for example, if you have the following:

/this_word_should_be_in_the_url word

Then there will be an additional query parameter named text that will contain everything else after the slash command. If you just have one parameter then it should be simple to just trim and use the text query parameter but if you have multiple words and need to split them into something more meaningful, then you might have to use some regex or simple string split function.

It is documented at How do commands work. In this section they have provided the various query parameters that will get passed to your Slash Command External URL. For the weather example, the data posted as per the documentation is:

token=gIkuvaNzQIHg97ATvDxqgjtO team_id=T0001 team_domain=example channel_id=C2147483705 channel_name=test user_id=U2147483697 user_name=Steve command=/weather text=94070 response_url=https://hooks.slack.com/commands/1234/5678

Notice the text parameter in the above list.