Git Product home page Git Product logo

stackstorm-slack's Introduction

Slack Integration Pack

Pack which allows integration with Slack service.

Configuration

Copy the example configuration in slack.yaml.example to /opt/stackstorm/configs/slack.yaml and edit as required. Note: Actions post_message and post_attachment use the same post_message_action configuration.

  • post_message_action.webhook_url - Webhook URL.
  • post_message_action.channel - Channel to send the message to (e.g. #mychannel). If not specified, messages will be sent to the channel which is selected when configuring a webhook.
  • post_message_action.username - Default name of the user under which the messages will be posted. This setting can be overridden on per action basis.
  • post_message_action.icon_emoji - Default icon of the user under which the messages will be posted. This setting can be overridden on per action basis. If not provided, default value which is selected when configuring a webhook is used.
  • post_message_action.icon_url - Default icon url of the user under which the messages will be posted. This setting can be overridden on per action basis. If not provided, default value which is selected when configuring a webhook is used.
  • sensor.token - Authentication token used to authenticate against Real Time Messaging API.
  • sensor.strip_formatting - By default, Slack automatically parses URLs, images, channels, and usernames. This option removes formatting and only returns the raw data from the client (URL only today)
  • sensor.allow_bot_messages - Allow the sensor to be triggered by bot messages without the as_user attribute. Defaults to false in order to provide backwards compatibility

Note : When modifying the configuration in /opt/stackstorm/configs/ please remember to tell StackStorm to load these new values by running st2ctl reload --register-configs

Obtaining a Webhook URL

To configure a webhook and obtain a URL, go to https://[your company].slack.com/services/new/incoming-webhook, select a channel you would like the messages to be posted to and click on "Add Incoming WebHooks Integration" button.

Step 1

On the next page you will find an automatically generated webhook URL.

Step 2

Obtaining Auth Token

To obtain a token for a production use, you should follow the instructions on the following page - OAuth - User Authentication.

For testing purposes, you can use the same token as your browser based client uses.

This is a lot simpler than going through the whole oAuth flow, but because of the obvious security reasons and a temporary natural of the token, you should only use that token for testing and debugging

To do that, navigate to your Slack instance (e.g. mycompany.slack.com), open Chrome developer console, go to Network tab, filter on XHR requests and refresh the page. Find a request to file.list or a similar endpoint and in the right page, under the Requests Payload section you will see an item identified as Content-Disposition: form-data; name="token". This will contain the token that your client uses to authenticate.

Chrome developer console

Sensors

SlackSensor

Slack sensor monitors Slack for activity and dispatches a trigger for each message which is posted to a channel.

slack.message trigger

Example trigger payload:

{
    "user": {
        "first_name": "Tomaz",
        "last_name": "Muraus",
        "is_owner": false,
        "name": "kami",
        "real_name": "Tomaz Muraus",
        "is_admin": false,
        "id": "U0CCCCC"
    },
    "channel": {
        "topic": "",
        "id": "C0CCCCCC",
        "name": "test"
    },
    "timestamp": 1419164091,
    "timestamp_raw": "1419164091.00005",
    "text": "This is a test message."
}

Actions

The following actions are provided by the Slack pack.

  • post_message - Post a message to the specified channel using an incoming webhook.
  • post_attachment - Post an attachment to the specified channel using an incoming webhook.
  • users.admin.invite - Send an invitation to join a Slack Org.
  • users_filter_by - List users in a Slack team matching certain creterias.

All other actions are as documented on the Slack API Methods page.

Let's consider the chat.postMessage method. You'll notice that it lists 14 parameters. Three of the 14 parameters are required, and the remainder are optional.

You can also list the actions available in st2 using st2 action list -p slack, and get help on each action using st2 action get slack.<action>, where <action> is the name of an action. Given our above example action:

root@c603fc2f139a:/opt/stackstorm/packs.dev/slack# st2 action list -p slack
+-------------------------------+-------+--------------------------------------------------------------+
| ref                           | pack  | description                                                  |
+-------------------------------+-------+--------------------------------------------------------------+
...
| slack.chat.meMessage          | slack | This method sends a me message to a channel from the calling |
|                               |       | user.                                                        |
| slack.chat.postMessage        | slack | This method posts a message to a public channel, private     |
|                               |       | channel, or direct message/IM channel (Allows posting to any |
|                               |       | slack channel using the unique webhook url).                       |
| slack.chat.unfurl             | slack | This method attaches Slack app unfurl behavior to a          |
|                               |       | specified and relevant message.                              |
...
+-------------------------------+-------+--------------------------------------------------------------+
root@c603fc2f139a:/opt/stackstorm/packs.dev/slack# st2 action get slack.chat.postMessage
+-------------+--------------------------------------------------------------+
| Property    | Value                                                        |
+-------------+--------------------------------------------------------------+
| id          | 596d3f26cf8580020317b9ca                                     |
| uid         | action:slack:chat.postMessage                                |
| ref         | slack.chat.postMessage                                       |
| pack        | slack                                                        |
| name        | chat.postMessage                                             |
| description | This method posts a message to a public channel, private     |
|             | channel, or direct message/IM channel.                       |
| enabled     | True                                                         |
| entry_point | run.py                                                       |
| runner_type | python-script                                                |
| parameters  | {                                                            |
|             |     "username": {                                            |
|             |         "required": false,                                   |
|             |         "type": "string"                                     |
|             |     },                                                       |
|             |     "thread_ts": {                                           |
|             |         "required": false,                                   |
|             |         "type": "string"                                     |
|             |     },                                                       |
|             |     "attachments": {                                         |
|             |         "required": false,                                   |
|             |         "type": "string"                                     |
|             |     },                                                       |
|             |     "unfurl_links": {                                        |
|             |         "required": false,                                   |
|             |         "type": "string"                                     |
|             |     },                                                       |
|             |     "end_point": {                                           |
|             |         "default": "chat.postMessage",                       |
|             |         "type": "string",                                    |
|             |         "immutable": true                                    |
|             |     },                                                       |
|             |     "link_names": {                                          |
|             |         "required": false,                                   |
|             |         "type": "string"                                     |
|             |     },                                                       |
|             |     "unfurl_media": {                                        |
|             |         "required": false,                                   |
|             |         "type": "string"                                     |
|             |     },                                                       |
|             |     "parse": {                                               |
|             |         "required": false,                                   |
|             |         "type": "string"                                     |
|             |     },                                                       |
|             |     "token": {                                               |
|             |         "required": false,                                   |
|             |         "type": "string"                                     |
|             |     },                                                       |
|             |     "text": {                                                |
|             |         "required": true,                                    |
|             |         "type": "string"                                     |
|             |     },                                                       |
|             |     "icon_emoji": {                                          |
|             |         "required": false,                                   |
|             |         "type": "string"                                     |
|             |     },                                                       |
|             |     "as_user": {                                             |
|             |         "required": false,                                   |
|             |         "type": "string"                                     |
|             |     },                                                       |
|             |     "icon_url": {                                            |
|             |         "required": false,                                   |
|             |         "type": "string"                                     |
|             |     },                                                       |
|             |     "channel": {                                             |
|             |         "required": true,                                    |
|             |         "type": "string"                                     |
|             |     },                                                       |
|             |     "reply_broadcast": {                                     |
|             |         "required": false,                                   |
|             |         "type": "string"                                     |
|             |     }                                                        |
|             | }                                                            |
| notify      |                                                              |
| tags        |                                                              |
+-------------+--------------------------------------------------------------+

Notice how there are 15 parameters. The extra one is "end_point", which is used by run.py to construct the end point URL.

Uploading files with slack.files.upload

The action slack.files.upload is able to upload files to slack, such as pictures. This action works a bit different than other actions in that the file_path parameter accepts a path to a file on the local filesystem. This path must be accessible from the the st2actionrunner executing the action. The st2actionrunner will open up the file path, read the contents and then upload this data to Slack as part of the action run.

Example:

st2 run slack.files.upload file_path=/opt/data/mycoolimage.png filename=mycoolimage.png

If this is not desirabile and you would rather read the file or pass the data yourself, this can be accomplished using the file or content parameters which both accept raw data that will be uploaded.

Developer Reference

How to auto-generate actions

If you're a pack developer working on this pack and want to auto-generate / update the actions here, please see bin/README.md

stackstorm-slack's People

Contributors

amanda11 avatar arm4b avatar armab avatar blag avatar centromikeb avatar chandugit avatar cognifloyd avatar dw-seanelliott avatar emedvedev avatar jfryman avatar kami avatar keslerm avatar kirilstrax avatar lindsayhill avatar longfei-zhang avatar manasdk avatar mbrannigan avatar mierdin avatar moisesrt avatar murthysrd avatar namachieli avatar nevdull77 avatar nmaludy avatar obynio avatar piroszhog avatar satellite-no avatar shusugmt avatar tonybaloney avatar vutny avatar warrenvw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stackstorm-slack's Issues

Slack pack won't install on python 3.8

The slack pack won't install on 3.5dev on focal and complains first with:

      1 | #include "libxml/xpath.h"
        |          ^~~~~~~~~~~~~~~~
  compilation terminated.
  *********************************************************************************
  Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?

Installing libxml2-dev and libxslt1-dev resolves this problem, but then the following problem is seen:

    x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/libxml2 -Isrc/lxml/includes -I/opt/stackstorm/virtualenvs/slack/include -I/usr/include/python3.8 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-3.8/src/lxml/lxml.etree.o -w
    src/lxml/lxml.etree.c: In function __Pyx_PyCFunction_FastCall:
    src/lxml/lxml.etree.c:233279:13: error: too many arguments to function (PyObject * (*)(PyObject *, PyObject * const*, Py_ssize_t))meth
    233279 |     return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs, NULL);
           |            ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    src/lxml/lxml.etree.c: In function __Pyx_PyDict_Items:
    src/lxml/lxml.etree.c:4532:83: error: too many arguments to function (PyObject * (*)(PyObject *, PyObject * const*, Py_ssize_t))__pyx_umethod_PyDict_Type_items.func

lxml < 4.0.0 doesn't support python 3.8, and so for focal need to use newer version of lxml.

Proposal: consistent action auto-generation

Background

There is no up-to-date API spec for Slack Web API available in the world today. There are some places that OpenAPI based specs are published, but all of them are out of sync with the latest API, even those from official ones.

For e.g. slack.chat.postMessage should include blocks argument according to the published html doc here, but it never appears in all of the above.

Quick look at https://github.com/slackapi/slack-api-specs/issues indicates that this repo seems to be abandoned?

So the only method we have left is scraping, which is exactly the way we are doing for now to auto-generate action meta yaml files. But this also have some problems.

Significant one is its unstableness of the page structure. When I run slack_api_gen.py today to apply updates on parameters to some actions, the action description fields become empty. After quick debugging, I found out that the html element previously used to fill in this field disappeared. And there seems no equivalent or good alternative for populating description.

The other major problem we have is the parameter type all marked as string. This is because the type is not clearly stated in the html doc, so we can't infer what type the parameter accepts. This makes users a bit confusing when passing Booelan-ish parameter. The action expects it passed in string type, so user need to pass "True" not True. The same thing happens to other types like numbers.

Proposal

For short term, action description should be replaced with some fixed string like:
This action is auto-generated. See https://api.slack.com/methods/chat.postMessage
And never tries to fill in from their html page.

For next, it may worth trying to combine the scraping + (outdated) OpenAPI spec. First we scrape, at this time the action description is the fixed string suggested above and all the parameter types are marked as string. After this we can complement action description, parameter types and even parameter descriptions from OpenAPI spec. There are some missing parameters or even API endpoint itself in current OpenAPI spec, but we at least can cover them at scraping stage so they won't be missing.

In the future, hopefully we can count on OpenAPI spec that is up-to-date.

How do I use files.upload?

I can get files.upload with text that is not very large using the content variable. But I would like to know how to use the file variable to actually upload a larger set of string data. I have tried several methods and have not been able to get it to work.

I have:
1: Passed in the long string to file - failed
2: Created a tempfile and specified the file location in the file variable - failed

I have tried other iterations both those are the basic ones that I have used.

Slack sensor - TypeError: expected string or buffer

I'm getting this error while activating sensor/trigger for slack messages. Am I missing something to be configured? I can successfully invoke services like post_message, channels.list, users.list, etc.

May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,082 ERROR [-] Traceback (most recent call last):
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,083 ERROR [-]   File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2reactor/container/sensor_wrapper.py", line 362, in <module>
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,084 ERROR [-]
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,085 ERROR [-] obj.run()
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,085 ERROR [-]   File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2reactor/container/sensor_wrapper.py", line 219, in run
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,086 ERROR [-]
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,087 ERROR [-] self._sensor_instance.setup()
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,087 ERROR [-]   File "/opt/stackstorm/packs/slack/sensors/slack_sensor.py", line 56, in setup
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,088 ERROR [-]
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,088 ERROR [-] self._populate_cache(user_data=self._api_call('users.list'),
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,089 ERROR [-]   File "/opt/stackstorm/packs/slack/sensors/slack_sensor.py", line 260, in _api_call
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,089 ERROR [-]
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,090 ERROR [-] result = json.loads(result)
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,090 ERROR [-]   File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,091 ERROR [-]
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,092 ERROR [-] return _default_decoder.decode(s)
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,092 ERROR [-]   File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,093 ERROR [-]
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,094 ERROR [-] obj, end = self.raw_decode(s, idx=_w(s, 0).end())
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,094 ERROR [-] TypeError
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,095 ERROR [-] :
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,096 ERROR [-] expected string or buffer
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,096 ERROR [-]
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,097 INFO [-] Stopping trigger watcher
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,098 INFO [-] Invoking cleanup on sensor

RuntimeError: dictionary changed size during iteration

st2 run slack.chat.postMessage token="" text="This is test notification" channel=""
.
id: 5f1f0194f22c04cacf04fb64
action.ref: slack.chat.postMessage
context.user: user
parameters:
channel:
text: This is test notification
token:
status: failed
start_timestamp: Mon, 27 Jul 2020 16:32:20 UTC
end_timestamp: Mon, 27 Jul 2020 16:32:20 UTC
result:
exit_code: 1
result: None
stderr: "Traceback (most recent call last):
File "/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py", line 333, in
obj.run()
File "/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py", line 192, in run
output = action.run(**self._parameters)
File "/opt/stackstorm/packs/slack/actions/run.py", line 30, in run
for key in params.keys():
RuntimeError: dictionary changed size during iteration
"
stdout: ''

Slack Channel ID Search

Hey folks!

Recently I had need to find the ID of a channel based on it's name during some internal development at work. I'd be happy to add the action, but it's not something that the Slack API offers out of the box, so it wouldn't conform to the generated actions here.

Attachment not working in chat.postMessage

I'm using your amazing pack, however, I cannot make the attachment to work with all the options I tried:

        name: "slack_ok"
        ref: "slack.chat.postMessage"
        parameters:
             username: "username"
             channel: "{{ slack_channel }}"
             attachments: "{\"text\":\"test\"}"

tried:
attachments: "{"text":"test"}"
attachments: "{["text":"test"]}"
attachments: "text: test"
attachments: ""text":"test""

In all scenarios I get no text:

st2.actions.python.SlackAction: ERROR Failed to perform action chat.postMessage: {"ok":false,"error":"no_text"} (status code: 200)
None
Traceback (most recent call last):
File "/opt/stackstorm/runners/python_runner/python_runner/python_action_wrapper.py", line 320, in
obj.run()
File "/opt/stackstorm/runners/python_runner/python_runner/python_action_wrapper.py", line 179, in run
output = action.run(**self._parameters)
File "/opt/stackstorm/packs/slack/actions/run.py", line 16, in run
return self._do_request(kwargs)
File "/opt/stackstorm/packs/slack/actions/run.py", line 78, in _do_request
raise Exception(failure_reason)
Exception: Failed to perform action chat.postMessage: {"ok":false,"error":"no_text"} (status code: 200)

Any help will be appreciated

Code seems to have compatibility issues with 3.7

The run.py file is using dict.iteritems() function call on line 44. The iteritems function call is deprecated now and is throwing error

stderr: "Traceback (most recent call last):
File "/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py", line 333, in
obj.run()
File "/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py", line 192, in run
output = action.run(**self._parameters)
File "/opt/stackstorm/packs/slack/actions/run.py", line 64, in run
data = urlencode(encode_obj(params))
File "/opt/stackstorm/packs/slack/actions/run.py", line 60, in encode_obj
return encode_dict(in_obj)
File "/opt/stackstorm/packs/slack/actions/run.py", line 44, in encode_dict
for k, v in in_dict.iteritems():
AttributeError: 'dict' object has no attribute 'iteritems'

Token is now set as a required parameter in actions, regardless of pack config.

With the recent update #55 which fixed the auto-generator (BIG thank you!), actions were re-generated. Since the data that is scrapes marked fields like token as required (which makes sense from the perspective of the documentation), actions are now set with

token:
  required: true

c391438#diff-2789753f4da93060f8810cbd4e3b55d4R63

This causes issues when you use the pack config for this token, as the action will not attempt to run since a required parameter is missing.

Im not sure the best course of action, but perhaps modifying the auto-gen logic to look for this key and override it being required?

run.py incompatible logic in python 3.x

dictionary changed size during iteration

Traceback (most recent call last):
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py\", line 333, in <module>
    obj.run()
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py\", line 192, in run
    output = action.run(**self._parameters)
  File \"/opt/stackstorm/packs/slack/actions/run.py\", line 19, in run
    return self._do_request(kwargs)
  File \"/opt/stackstorm/packs/slack/actions/run.py\", line 32, in _do_request
    for key in params.keys():
RuntimeError: dictionary changed size during iteration

for key in params.keys():

Based on the accepted answer in the Stack overflow discussion:, This needs to be updated to something like for key in list(params.keys()):

'dict' object has no attribute 'iteritems'

Traceback (most recent call last):
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py\", line 333, in <module>
    obj.run()
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py\", line 192, in run
    output = action.run(**self._parameters)
  File \"/opt/stackstorm/packs/slack/actions/run.py\", line 19, in run
    return self._do_request(kwargs)
  File \"/opt/stackstorm/packs/slack/actions/run.py\", line 61, in _do_request
    data = urlencode(encode_obj(params))
  File \"/opt/stackstorm/packs/slack/actions/run.py\", line 57, in encode_obj
    return encode_dict(in_obj)
  File \"/opt/stackstorm/packs/slack/actions/run.py\", line 46, in encode_dict
    for k, v in in_dict.iteritems():
AttributeError: 'dict' object has no attribute 'iteritems'

for k, v in in_dict.iteritems():

In 3.x iteritems() was replaced with items(), to ensure backwards compatibility a common approach has been to use six.iteritems(dict). In this case; for k, v in in_dict.iteritems(): should be replaced with for k, v in six.iteritems(in_dict):

Resolution

Checking for other instances of similar logic should be done. Additionally, test coverage would catch this sort of thing, so ideally testing should be created.

AttributeError: 'str' object has no attribute 'get' in mask_secrets in rule.py

SUMMARY

Provide a quick summary of your bug report.

STACKSTORM VERSION

Paste the output of st2 --version:

st2 3.2.0, on Python 2.7.5

OS, environment, install method

Post what OS you are running this on, along with any other relevant information/

RHEL 7.6 one-line install

Steps to reproduce the problem

Show how to reproduce the problem, using a minimal test-case. Make sure to include any content
(pack content - workflows, actions, etc.) which are needed to reproduce the problem.

  • install slack pack and define a rule to trigger slack.message trigger.
  • found error messages in st2rulesengine.log
2020-08-05 19:58:53,324 139647545789008 ERROR traceback [-] Traceback (most recent call last):

2020-08-05 19:58:53,325 139647545789008 ERROR traceback [-]   File "/usr/lib64/python2.7/logging/__init__.py", line 851, in emit

2020-08-05 19:58:53,325 139647545789008 ERROR traceback [-]     msg = self.format(record)

2020-08-05 19:58:53,326 139647545789008 ERROR traceback [-]   File "/usr/lib64/python2.7/logging/__init__.py", line 724, in format

2020-08-05 19:58:53,326 139647545789008 ERROR traceback [-]     return fmt.format(record)

2020-08-05 19:58:53,326 139647545789008 ERROR traceback [-]   File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/logging/formatters.py", line 176, in format

2020-08-05 19:58:53,327 139647545789008 ERROR traceback [-]     attributes = self._format_extra_attributes(attributes=attributes)

2020-08-05 19:58:53,327 139647545789008 ERROR traceback [-]   File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/logging/formatters.py", line 151, in _format_extra_attributes

2020-08-05 19:58:53,328 139647545789008 ERROR traceback [-]     value = serialize_object(obj=value)

2020-08-05 19:58:53,329 139647545789008 ERROR traceback [-]   File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/logging/formatters.py", line 65, in serialize_object

2020-08-05 19:58:53,329 139647545789008 ERROR traceback [-]     value = obj.to_serializable_dict(mask_secrets=True)

2020-08-05 19:58:53,330 139647545789008 ERROR traceback [-]   File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/models/db/stormbase.py", line 105, in to_serializable_dict

2020-08-05 19:58:53,330 139647545789008 ERROR traceback [-]     serializable_dict = self.mask_secrets(value=serializable_dict)

2020-08-05 19:58:53,330 139647545789008 ERROR traceback [-]   File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/models/db/rule.py", line 137, in mask_secrets

2020-08-05 19:58:53,331 139647545789008 ERROR traceback [-]     action_ref = result.get('action', {}).get('ref', None)

2020-08-05 19:58:53,331 139647545789008 ERROR traceback [-] AttributeError: 'str' object has no attribute 'get'

2020-08-05 19:58:53,331 139647545789008 ERROR handlers [-] Logged from file filter.py, line 94
  • add trace log in rule.py
       LOG.info('result in rule.py is %s - %s' % (type(result), result))
        LOG.info("result.get('action', {}) is %s = %s " % ( type(result.get('action', {})), result.get('action', {})))
  • found that return value of result.get('action', {}) is str
2020-08-05 19:53:08,139 140298075175504 INFO rule [-] result.get('action', {}) is <type 'str'> = ActionExecutionSpecDB@140298075004112(ref="slack.post_message", parameters="{u'debug': True, u'content_v
ersion': u'#test', u'message': u'test message to trigger', u'log_level': u'DEBUG', u'username': u'classic'}")

Expected Results

What did you expect to happen when running the steps above?

Actual Results

What happened? What output did you get?

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

channel info cannot be obtained by _get_channel_info in sensor

I modified poll function in packs/slack/sensors/slack_sensor.py to include debugging

    def _api_call(self, method, **kwargs):
        result = self._client.api_call(method, **kwargs)

        self._logger.info('inside _api_call ... %s  and %s ' %  (method, kwargs) )
        self._logger.info(result)
        self._logger.info(type(result))

        if isinstance(result, str):
            result = json.loads(result)

        return result

And when I type messages in a slack channel, the poll result error message says [u'[ERROR] This method is retired and can no longer be used. Please use conversations.info instead

2020-08-05 08:36:37,968 140520872485744 INFO slack_sensor [-] inside _api_call ... channels.info  and {'channel': u'CSDBKG7BP'}
2020-08-05 08:36:37,969 140520872485744 INFO slack_sensor [-] {u'headers': {u'content-length': u'222', u'x-xss-protection': u'0', u'x-content-type-options': u'nosniff', u'content-encoding': u'gzip', u'x-slack-req-id': u'3f18d6ff700b054bfbb82af86fe11638', u'access-control-expose-headers': u'x-slack-req-id, retry-after', u'vary': u'Accept-Encoding', u'x-via': u'haproxy-www-u6qh,haproxy-edge-iad-sgwj', u'expires': u'Mon, 26 Jul 1997 05:00:00 GMT', u'server': u'Apache', u'access-control-allow-origin': u'*', u'x-slack-backend': u'r', u'strict-transport-security': u'max-age=31536000; includeSubDomains; preload', u'pragma': u'no-cache', u'cache-control': u'private, no-cache, no-store, must-revalidate', u'date': u'Wed, 05 Aug 2020 15:36:37 GMT', u'x-oauth-scopes': u'identify,bot:basic', u'referrer-policy': u'no-referrer', u'content-type': u'application/json; charset=utf-8', u'access-control-allow-headers': u'slack-route, x-slack-version-ts, x-b3-traceid, x-b3-spanid, x-b3-parentspanid, x-b3-sampled, x-b3-flags'}, u'ok': False, u'response_metadata': {u'messages': [u'[ERROR] This method is retired and can no longer be used. Please use conversations.info instead. Learn more: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api.']}, u'error': u'method_deprecated'}
2020-08-05 08:36:37,970 140520872485744 INFO slack_sensor [-] <type 'dict'>
2020-08-05 08:36:37,970 140520872485744 INFO slack_sensor [-] channel_info is None

so there is no channel info returned by api call.

chat.update text parameter marked required, not when only using attachment

The text parameter in the action slack.chat.update is set to required: true. slack.chat.postMessage is not.

Looking at the details for the corresponding methods in slack's documentation the text parameter should only be required when not using any attachments

I propose that required: true should be removed and in the case where the action has neither specified, it be allowed to fail when the Slack API denies the request.

slack pack output not appearing under the same thread

There is a bug in the latest version of the slack pack whereby the output of a workflow is not displayed within the same thread. Instead the output is displayed as a seperate message in the channel. This bug did not exist in slack version 0.12.8. Please can we have the same behaviour in the latest version of slack?
Here is an example of the issue, notice that the output should've been displayed as a thread under "Checking ISP link and BGP status for dc NP-STH2-DC / isp all" instead of a seperate message:
image
image

Should we remove unofficial actions?

It seems that users.admin.invite endpoint is not officially supported nor documented, as that slack_api_gen.py does not generate an action metadata for it. But it is actually there and available for public use. Question is: should we keep this not officially support action? or remove?

Note: There seems to be several other hidden and/or unsupported API endpoints:
https://github.com/ErikKalkoken/slackApiDoc

can we encrypt the webhook and token parameter?

I don't want other user see webhook and token directly.
so maybe we can add the values like:

---
# Used for post message action
post_message_action:
  webhook_url: "I'm encrypted"
  channel: "#mychannel"
  username: "my-bot"
  icon_emoji: ":panda_face:"

# Used for Slack sensor
sensor:
  token: "I'm encrypted"
  strip_formatting: false

If so then st2 need to decrypt it first and then use it.

how post color message

I use slack.chat.postMessage, but attachments don't provide color and other options for formatting

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.