Message accepted for delivery
(data *MsgServerData, action int)
| 596 | |
| 597 | // Message accepted for delivery |
| 598 | func pluginMessage(data *MsgServerData, action int) { |
| 599 | if globals.plugins == nil || action != plgActCreate { |
| 600 | return |
| 601 | } |
| 602 | |
| 603 | var event *pbx.MessageEvent |
| 604 | for i := range globals.plugins { |
| 605 | p := &globals.plugins[i] |
| 606 | if p.filterMessage == nil || p.filterMessage.byAction&action == 0 { |
| 607 | // Plugin is not interested in Message actions |
| 608 | continue |
| 609 | } |
| 610 | |
| 611 | if event == nil { |
| 612 | event = &pbx.MessageEvent{ |
| 613 | Action: pluginActionToCrud(action), |
| 614 | Msg: pbServDataSerialize(data).Data, |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | var ctx context.Context |
| 619 | var cancel context.CancelFunc |
| 620 | if p.timeout > 0 { |
| 621 | ctx, cancel = context.WithTimeout(context.Background(), p.timeout) |
| 622 | defer cancel() |
| 623 | } else { |
| 624 | ctx = context.Background() |
| 625 | } |
| 626 | if _, err := p.client.Message(ctx, event); err != nil { |
| 627 | logs.Warn.Println("plugins: Message call failed", p.name, err) |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | // Returns false to skip, true to process |
| 633 | func pluginDoFiltering(filter *PluginFilter, msg *ClientComMessage) bool { |
no test coverage detected
searching dependent graphs…