2

I have created a hooks.slack.com/services webhook for Slack. This is done as a custom app, as is recommended by Slack as the correct way to do this in 2023.

This hook participates in the following flow:

AWS SNS event -> Lambda -> Slack hook -> message in Slack channel

I have created the following python AWS lambda which consumes an SNS event message and then sends a formatted version of it to my webhook.

import http.client
import json

def lambda_handler(event, context):
    url = "https://hooks.slack.com/services/<myurl>"
    headers = {"Content-type": "application/json"}
    
    msg = {
        "channel": "<my-channel-name>",
        "icon_url": "<my image url>",
        "blocks": [
            {
                "type": "section",
                "fields": [
                    {
                        "type": "mrkdwn",
                        "text": "*Alarm:* " + event["Records"][0]["Sns"]["Subject"]
                    }
                ]
            },
            {
                "type": "section",
                "fields": [
                    {
                        "type": "mrkdwn",
                        "text": "*Message:* " + event["Records"][0]["Sns"]["Message"]
                    }
                ]
            }
        ]
    }
    
    encoded_msg = json.dumps(msg).encode("utf-8")

    conn = http.client.HTTPSConnection("hooks.slack.com")
    conn.request("POST", url, encoded_msg, headers)
    response = conn.getresponse()

    print({
        "message": event["Records"][0]["Sns"]["Message"],
        "status_code": response.status,
        "response": response.read().decode()
    })

Slack renders messages received into my channel using the following icon:

enter image description here

I don't want this! How can I change it to something else?

I have tried setting icon_url in the message payload, but this is ignored.

Slack's documentation is unclear on this.

8bitjunkie
  • 12,793
  • 9
  • 57
  • 70
  • I have the same problem... did you find a way to resolve this? – Brent Jun 15 '23 at 12:17
  • @Brent afraid not, no, I ended up living with it. From memory, I believe there is some confusion between a former API (Webhooks?) and this current one and in the former, this value could be set, but in the current one, I don't believe it can be. – 8bitjunkie Jun 16 '23 at 14:03

0 Answers0