From 0aa24c6f3af5d1716d801cbd993258cbd9e08059 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Fri, 20 Sep 2024 15:05:26 +0200 Subject: [PATCH] Add methods to retrieve message ID and message from SendError Implement MessageID and Msg methods in SendError to allow retrieval of the message ID and the affected message, respectively. These methods handle cases where the error or the message is nil, returning an empty string or nil as appropriate. --- senderror.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/senderror.go b/senderror.go index 494bfd3..90c8c4a 100644 --- a/senderror.go +++ b/senderror.go @@ -118,6 +118,23 @@ func (e *SendError) IsTemp() bool { return e.isTemp } +// MessageID returns the message ID of the affected Msg that caused the error +// If no message ID was set for the Msg, an empty string will be returned +func (e *SendError) MessageID() string { + if e == nil || e.affectedMsg == nil { + return "" + } + return e.affectedMsg.GetMessageID() +} + +// Msg returns the pointer to the affected message that caused the error +func (e *SendError) Msg() *Msg { + if e == nil || e.affectedMsg == nil { + return nil + } + return e.affectedMsg +} + // String implements the Stringer interface for the SendErrReason func (r SendErrReason) String() string { switch r {