slack-go / slack

Slack API in Go, originally by @nlopes; Maintainers needed, contact @parsley42
https://pkg.go.dev/github.com/slack-go/slack
BSD 2-Clause "Simplified" License
4.7k stars 1.14k forks source link

[AppMentionEvent] can not get grafana alerts text #1151

Open sven0219 opened 1 year ago

sven0219 commented 1 year ago

What happened

image As shown in the screenshot, I use grafana to send a test alerts, but the text of the alerts cannot be obtained in slackbot. The following is my code

func middlewareAppMentionEvent(evt *socketmode.Event, client *socketmode.Client) {
    eventsAPIEvent, ok := evt.Data.(slackevents.EventsAPIEvent)
    if !ok {
        logger.Info("Ignored %+v\n", evt)
        return
    }
    client.Ack(*evt.Request)
    ev, ok := eventsAPIEvent.InnerEvent.Data.(*slackevents.AppMentionEvent)
    logger.Info("evText----------->", ev.Text)
    logger.Info("evType----------->", ev.Type)
    if !ok {
        logger.Info("Ignored %+v\n", ev)
        return
    }
...
...

The log is as follows

...
{"level":"info","ts":"2022-12-22T09:44:42+08:00","msg":"evText-----------> "}
{"level":"info","ts":"2022-12-22T09:44:42+08:00","msg":"evType----------->app_mention"}
...

Expected behavior

When I ping the robot like this image the logs like this:

...
{"level":"info","ts":"2022-12-22T10:00:57+08:00","msg":"evText-----------><@U03***LRF>  Hello world"}
{"level":"info","ts":"2022-12-22T10:00:57+08:00","msg":"evType----------->app_mention"}
...

I'm not sure why I can't get the grafana alerts text

Versions

kanata2 commented 1 year ago

Could you try to log evt.Data?

sven0219 commented 1 year ago

Sorry for reply so late. Code for log evt.Data

func middlewareAppMentionEvent(evt *socketmode.Event, client *socketmode.Client) {
    eventsAPIEvent, ok := evt.Data.(slackevents.EventsAPIEvent)
    logger.Info("evt.Data---->", evt.Data)
    if !ok {
        logger.Info("Ignored %+v\n", evt)
        return
    }
...

log

{"level":"info","ts":"2023-01-11T18:07:09+08:00","msg":"evt.Data---->{AwKZMkAdB1AbFuoc6sn1j9fA T024GQDB5 event_callback A03GSSXUTNY  0xc0000ca460 {app_mention 0xc0000ca500}}"}

slack msg

image
github-actions[bot] commented 1 year ago

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.