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

Error trying uload file on chats slack with new backend #71

Open
litr0x opened this issue Jul 21, 2022 · 2 comments
Open

Error trying uload file on chats slack with new backend #71

litr0x opened this issue Jul 21, 2022 · 2 comments

Comments

@litr0x
Copy link

litr0x commented Jul 21, 2022

i triying to upload a file to a slack chat. This is a complete log

2022-07-18 17:13:51,398 ERROR errbot.backends.slackv3 Upload of archivos-R107-H02.tar.gz to coordinación-entregas failed.
Traceback (most recent call last):
File "/errbot-dir/backend/err-backend-slackv3/slackv3.py", line 752, in _slack_upload
resp = self.slack_web.files_upload(
File "/usr/lib/python3.9/site-packages/slack_sdk/web/client.py", line 2975, in files_upload
return self.api_call("files.upload", files={"file": file}, data=kwargs)
File "/usr/lib/python3.9/site-packages/slack_sdk/web/base_client.py", line 156, in api_call
return self._sync_send(api_url=api_url, req_args=req_args)
File "/usr/lib/python3.9/site-packages/slack_sdk/web/base_client.py", line 187, in _sync_send
return self._urllib_api_call(
File "/usr/lib/python3.9/site-packages/slack_sdk/web/base_client.py", line 309, in _urllib_api_call
return SlackResponse(
File "/usr/lib/python3.9/site-packages/slack_sdk/web/slack_response.py", line 189, in validate
raise e.SlackApiError(message=msg, response=self)
slack_sdk.errors.SlackApiError: The request to the Slack API failed. (url: https://www.slack.com/api/files.upload)
The server responded with: {'ok': False, 'error': 'invalid_channel', 'channel': '<#GCP4E5A1G|coordinación-entregas>'}
@sijis
Copy link
Collaborator

sijis commented Jul 21, 2022

Could you include an example of what the botcmd you were using to do this? If it's a custom botcmd, would also be able to include a snippet of it?

@drjeep
Copy link

drjeep commented Mar 24, 2024

I have the same issue. My botcmd looks something like this

@arg_botcmd("job_id", type=int, name="get-jenkins-log")
def get_jenkins_log(self, msg, job_id):
    try:
        to = msg.frm.room
    except AttributeError:
        to = msg.frm

    body = Command.get_jenkins_job_log(job_id)

    self.send_stream_request(
        user=to,
        fsource=BytesIO(
            bytes(
                body,
                "utf-8",
            )
        ),
    )

The issue seems to be that to.channelid contains <#C12345|channel-name> instead of just C12345 that Slack expects. In my case the fix is changing stream.identifier.channelid to stream.identifier.id in _slack_upload

def _slack_upload(self, stream: Stream) -> None:
    """
    Performs an upload defined in a stream
    :param stream: Stream object
    :return: None
    """
    try:
        stream.accept()
        resp = self.slack_web.files_upload(
            channels=stream.identifier.id, filename=stream.name, file=stream
        )
        if resp.get("ok"):
            stream.success()
        else:
            stream.error()
    except Exception:
        log.exception(f"Upload of {stream.name} to {stream.identifier.channelname} failed.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants