Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community.general.slack: Private Channel ID's are not found #2608

Open
ghost opened this issue May 25, 2021 · 8 comments
Open

community.general.slack: Private Channel ID's are not found #2608

ghost opened this issue May 25, 2021 · 8 comments
Labels
bug This issue/PR relates to a bug has_pr module module notification plugins plugin (any type)

Comments

@ghost
Copy link

ghost commented May 25, 2021

Summary

When I try to modify a message from a private channel, I am returned a "channel_not_found" message. Looking into the code is seems that the slack.py build_payload_for_slack() function is looking for channels that start with ('#', '@', 'C0') but private channels start with G0#### and a "#" is prefixed into the channel id which misnames the channel id.

def build_payload_for_slack(module, text, channel, thread_id, username, icon_url, icon_emoji, link_names,
                            parse, color, attachments, blocks, message_id):
    payload = {}
    if color == "normal" and text is not None:
        payload = dict(text=escape_quotes(text))
    elif text is not None:
        # With a custom color we have to set the message as attachment, and explicitly turn markdown parsing on for it.
        payload = dict(attachments=[dict(text=escape_quotes(text), color=color, mrkdwn_in=["text"])])
    if channel is not None:
        if channel.startswith(('#', '@', 'C0')):
            payload['channel'] = channel
        else:
            payload['channel'] = '#' + channel

Issue Type

Bug Report

Component Name

slack

Ansible Version

$ ansible --version
ansible [core 2.11.0] 

Configuration

$ ansible-config dump --only-changed

OS / Environment

No response

Steps to Reproduce

- name: Slack Test Playbook
  hosts: localhost

  tasks:
    - name: Slack Update of status
      community.general.slack:
        channel: private_channel
        token: "{{ web_api_token }}"
        msg: "Hello "
      register: slack_result

    - name:  update the message
      community.general.slack:
        channel: "{{ slack_result.channel }}"
        token: ""{{ web_api_token }}"
        msg: "Hello Again"
        message_id: "{{ slack_result.ts }}"

Expected Results

I expected the message to be updated but instead received a channel not found.

Actual Results

    "changed": false,
    "error": "channel_not_found",
    "invocation": {
        "module_args": {
            "attachments": null,
            "blocks": null,
            "channel": "G0####",
            "color": "normal",
            "domain": null,
            "icon_emoji": null,
            "icon_url": "https://www.ansible.com/favicon.ico",
            "link_names": 1,
            "message_id": "1622501431.003800",
            "msg": "Hello Again",
            "parse": null,
            "thread_id": null,
            "token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "username": "Ansible",
            "validate_certs": true
        }
    },
    "msg": "Slack API error"
}```
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added affects_2.11 bug This issue/PR relates to a bug module module needs_triage notification plugins plugin (any type) labels May 25, 2021
@felixfontein
Copy link
Collaborator

I guess if channel.startswith(('#', '@', 'C0')): should be changed to if channel.startswith(('#', '@', 'C0', 'G0')): then. Can you test whether that fixes your issue?

@aminvakil
Copy link
Contributor

@cchang10222 If you have tested #2608 (comment) fixed your issue, are you interested in making a PR fixing this for everyone using module?

@ghost
Copy link
Author

ghost commented May 27, 2021

@aminvakil @felixfontein I tested and this did fix my issue, I could give it a try and open a PR for this.

@aminvakil
Copy link
Contributor

@cchang10222 Great!

@aminvakil
Copy link
Contributor

aminvakil commented Jul 5, 2021

@cchang10222 Are you still planning to work on this?

You can also take a look at create pr quick start guide.

@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug has_pr module module notification plugins plugin (any type)
Projects
None yet
Development

No branches or pull requests

3 participants