2
votes

I am trying to remove a button block from a message I posted via a bot

But when my app calls, it results in an internal_error response

params={
            "channel":channel_id, # same as via api.slack.com
            "ts":msg_ts, # same as via api.slack.com
            "text":msg, # same as via api.slack.com
            "token":APP_TOKEN, # same as via api.slack.com
            "blocks":[img_block] # same as via api.slack.com, dict (see below for value)
        }
r = requests.post("https://slack.com/api/chat.update", params)

The blocks part, which is the key changing part (I first get all blocks, then I remove the button block by only posting the image block), I see in dev tools in chrome from https://api.slack.com/methods/chat.update/test equals the one of my app

blocks: [{'type': 'image', 'block_id': 'qtl', 'image_url': 'https://.s3.eu-central-1.amazonaws.com//tmp/filename.png', 'alt_text': 'ALT', 'title': {'type': 'plain_text', 'text': 'TEXT'}}]

blocks: [{'type': 'image', 'block_id': 'qtl', 'image_url': 'https://.s3.eu-central-1.amazonaws.com//tmp/filename.png', 'alt_text': 'ALT', 'title': {'type': 'plain_text', 'text': 'TEXT'}}]

Is this a bug? The API documentation states the following

The server could not complete your operation(s) without encountering an error, likely due to a transient issue on our end. It's possible some aspect of the operation succeeded before the error was raised.

Anything else I could try?

1
I am facing the same issue right now. - Gautam
Ok that's a very valuable information, might really be a bug. - Nico Müller
Just make sure your JSON structure is correct. I was getting this error because of the incorrect JSON structure. It's working for me now, so it's not an issue with slack. - Gautam

1 Answers

1
votes

I finally got it working (thanks @Gautam for pushing me to look another time into this)

I now added the Token again in the headers additionally to having the token in the params.. The response/documentation could have been a bit clearer about this

headers = {'Content-Type': 'application/json', 'Accept':'application/json', 'charset':'utf-8', 'Authorization': f'Bearer {APP_TOKEN}'}
r = requests.post("https://slack.com/api/chat.update", json=params, headers=headers)