Debian Codegraph @

pkg/services/chat/signal/signal.go

raw symbols SCIP
1 package signalscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/
2
3 import (
4 "bytesscip-go gomod github.com/golang/go/src . bytes/"
5 "contextscip-go gomod github.com/golang/go/src . context/"
6 "encoding/jsonscip-go gomod github.com/golang/go/src . `encoding/json`/"
7 "fmtscip-go gomod github.com/golang/go/src . fmt/"
8 "net/httpscip-go gomod github.com/golang/go/src . `net/http`/"
9 "net/urlscip-go gomod github.com/golang/go/src . `net/url`/"
10 "stringsscip-go gomod github.com/golang/go/src . strings/"
11 "timescip-go gomod github.com/golang/go/src . time/"
12
13 "github.com/nicholas-fedor/shoutrrr/pkg/formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/"
14 "github.com/nicholas-fedor/shoutrrr/pkg/services/standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/"
15 "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/"
16 )
17
18 // Service sends notifications to Signal recipients via signal-cli-rest-api.
19 type Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service# struct {
20 standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/.Standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#Standard.
21
22 Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#Config. *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#
23 pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#pkr. formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.PropKeyResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/PropKeyResolver#
24 httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#httpClient. typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/HTTPClient#
25 }
26
27 // HTTP request timeout duration.
28 const (
29 defaultHTTPTimeoutscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/defaultHTTPTimeout. = 30 * timescip-go gomod github.com/golang/go/src . time/.Secondscip-go gomod github.com/golang/go/src . time/Second.
30 )
31
32 // GetID returns the identifier for this service.
33 //
34 // Returns:
35 // - string: the service identifier.
36 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#) GetIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#GetID().() string {
37 return Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Scheme.
38 }
39
40 // Initialize configures the service with a URL and logger.
41 //
42 // Parameters:
43 // - serviceURL: the configuration URL for the Signal service
44 // - logger: the logger to use for logging
45 //
46 // Returns:
47 // - error: if configuration fails, nil otherwise
48 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#) Initializescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#Initialize().(serviceURL *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#, logger typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.StdLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/StdLogger#) error {
49 s.SetLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Logger#SetLogger().(logger)
50 s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#Config. = &Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#{}
51 s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#pkr. = formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.NewPropKeyResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/NewPropKeyResolver().(s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#Config.)
52
53 if err := s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#Config..setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#setURL().(&s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#pkr., serviceURL); err != nil {
54 return err
55 }
56
57 return nil
58 }
59
60 // Send delivers a notification message to Signal recipients.
61 //
62 // Parameters:
63 // - message: the text message to send
64 // - params: optional parameters (e.g., attachments)
65 //
66 // Returns:
67 // - error: if the send operation fails, nil otherwise
68 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#) Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#Send().(message string, params *typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#) error {
69 config := *s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#Config.
70
71 // Separate config params from message params (like attachments)
72 var (
73 configParams *typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#
74 messageParams *typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#
75 )
76
77 if params != nil {
78 configParams = &typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#{}
79 messageParams = &typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#{}
80
81 for key, value := range *params {
82 // Check if this is a config parameter
83 if _, err := s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#pkr..Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/PropKeyResolver#Get().(key); err == nil {
84 // It's a valid config key
85 (*configParams)[key] = value
86 } else {
87 // It's a message parameter (like attachments)
88 (*messageParams)[key] = value
89 }
90 }
91
92 if err := s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#pkr..UpdateConfigFromParamsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/PropKeyResolver#UpdateConfigFromParams().(&config, configParams); err != nil {
93 return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("updating config from params: %w", err)
94 }
95 }
96
97 return s.sendMessagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#sendMessage().(message, &config, messageParams)
98 }
99
100 // SetHTTPClient sets a custom HTTP client for the service.
101 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#) SetHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#SetHTTPClient().(client typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/HTTPClient#) {
102 s.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#httpClient. = client
103 }
104
105 // buildAPIURL constructs the Signal API endpoint URL from the configuration.
106 //
107 // Parameters:
108 // - config: the service configuration
109 //
110 // Returns:
111 // - string: the full API endpoint URL
112 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#) buildAPIURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#buildAPIURL().(config *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#) string {
113 scheme := "https"
114 if config.DisableTLSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#DisableTLS. {
115 scheme = "http"
116 }
117
118 return fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("%s://%s:%d/v2/send", scheme, config.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#Host., config.Portscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#Port.)
119 }
120
121 // createPayload builds the JSON payload for the Signal API request.
122 //
123 // Parameters:
124 // - message: the message text
125 // - config: the service configuration
126 // - params: optional parameters (may include attachments)
127 //
128 // Returns:
129 // - sendMessagePayload: the payload struct to be sent
130 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#) createPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#createPayload().(
131 message string,
132 config *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#,
133 params *typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#,
134 ) sendMessagePayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/sendMessagePayload# {
135 payload := sendMessagePayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/sendMessagePayload#{
136 Messagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/sendMessagePayload#Message.: message,
137 Numberscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/sendMessagePayload#Number.: config.Sourcescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#Source.,
138 Recipientsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/sendMessagePayload#Recipients.: config.Recipientsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#Recipients.,
139 Base64Attachmentsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/sendMessagePayload#Base64Attachments.: nil, // will be set if attachments provided
140 }
141
142 // Check for attachments in params (passed during Send call)
143 // Note: Shoutrrr doesn't have a standard attachment interface,
144 // so we check for "attachments" parameter with base64 data
145 if params != nil {
146 if attachments, ok := (*params)["attachments"]; ok && attachments != "" {
147 // Parse comma-separated base64 attachments
148 attachmentList := stringsscip-go gomod github.com/golang/go/src . strings/.Splitscip-go gomod github.com/golang/go/src . strings/Split().(attachments, ",")
149 for i, attachment := range attachmentList {
150 attachmentList[i] = stringsscip-go gomod github.com/golang/go/src . strings/.TrimSpacescip-go gomod github.com/golang/go/src . strings/TrimSpace().(attachment)
151 }
152
153 payload.Base64Attachmentsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/sendMessagePayload#Base64Attachments. = attachmentList
154 }
155 }
156
157 return payload
158 }
159
160 // createRequest builds the HTTP request for the Signal API.
161 //
162 // Parameters:
163 // - config: the service configuration
164 // - payload: the payload to send (passed as pointer for efficiency)
165 //
166 // Returns:
167 // - *http.Request: the constructed HTTP request
168 // - context.CancelFunc: a function to cancel the request context
169 // - error: if request creation fails, nil otherwise
170 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#) createRequestscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#createRequest().(
171 config *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#,
172 payload *sendMessagePayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/sendMessagePayload#,
173 ) (*httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#, contextscip-go gomod github.com/golang/go/src . context/.CancelFuncscip-go gomod github.com/golang/go/src . context/CancelFunc#, error) {
174 apiURL := s.buildAPIURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#buildAPIURL().(config)
175
176 jsonData, err := jsonscip-go gomod github.com/golang/go/src . `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src . `encoding/json`/Marshal().(payload)
177 if err != nil {
178 return nil, nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("marshaling payload to JSON: %w", err)
179 }
180
181 ctx, cancel := contextscip-go gomod github.com/golang/go/src . context/.WithTimeoutscip-go gomod github.com/golang/go/src . context/WithTimeout().(
182 contextscip-go gomod github.com/golang/go/src . context/.Backgroundscip-go gomod github.com/golang/go/src . context/Background().(),
183 defaultHTTPTimeoutscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/defaultHTTPTimeout.,
184 )
185
186 req, err := httpscip-go gomod github.com/golang/go/src . `net/http`/.NewRequestWithContextscip-go gomod github.com/golang/go/src . `net/http`/NewRequestWithContext().(
187 ctx,
188 httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodPostscip-go gomod github.com/golang/go/src . `net/http`/MethodPost.,
189 apiURL,
190 bytesscip-go gomod github.com/golang/go/src . bytes/.NewBufferscip-go gomod github.com/golang/go/src . bytes/NewBuffer().(jsonData),
191 )
192 if err != nil {
193 cancel()
194
195 return nil, nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("creating HTTP request: %w", err)
196 }
197
198 req.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", "application/json")
199 s.setAuthenticationscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#setAuthentication().(req, config)
200
201 return req, cancel, nil
202 }
203
204 // httpClientOrDefault returns the injected client or a default client.
205 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#) httpClientOrDefaultscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#httpClientOrDefault().() typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/HTTPClient# {
206 if s.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#httpClient. != nil {
207 return s.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#httpClient.
208 }
209
210 return &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{Timeoutscip-go gomod github.com/golang/go/src . `net/http`/Client#Timeout.: defaultHTTPTimeoutscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/defaultHTTPTimeout.}
211 }
212
213 // parseResponse reads and logs the response from the Signal API.
214 //
215 // Parameters:
216 // - resp: the HTTP response to parse
217 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#) parseResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#parseResponse().(resp *httpscip-go gomod github.com/golang/go/src . `net/http`/.Responsescip-go gomod github.com/golang/go/src . `net/http`/Response#) {
218 var response sendMessageResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/sendMessageResponse#
219 if err := jsonscip-go gomod github.com/golang/go/src . `encoding/json`/.NewDecoderscip-go gomod github.com/golang/go/src . `encoding/json`/NewDecoder().(resp.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body.).Decodescip-go gomod github.com/golang/go/src . `encoding/json`/Decoder#Decode().(&response); err != nil {
220 s.Logfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Logger#Logf().("Warning: failed to parse response: %v", err)
221 } else {
222 s.Logfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Logger#Logf().("Message sent successfully at timestamp %d", response.Timestampscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/sendMessageResponse#Timestamp.)
223 }
224 }
225
226 // sendMessage sends a message to all configured recipients.
227 //
228 // Parameters:
229 // - message: the message text to send
230 // - config: the service configuration
231 // - params: optional parameters (e.g., attachments)
232 //
233 // Returns:
234 // - error: if sending fails, nil otherwise
235 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#) sendMessagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#sendMessage().(message string, config *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#, params *typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#) error {
236 if len(config.Recipientsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#Recipients.) == 0 {
237 return ErrNoRecipientsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/ErrNoRecipients.
238 }
239
240 payload := s.createPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#createPayload().(message, config, params)
241
242 req, cancel, err := s.createRequestscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#createRequest().(config, &payload)
243 if err != nil {
244 return err
245 }
246 defer cancel()
247
248 return s.sendRequestscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#sendRequest().(req)
249 }
250
251 // sendRequest executes the HTTP request and processes the response.
252 //
253 // Parameters:
254 // - req: the HTTP request to execute
255 //
256 // Returns:
257 // - error: if the request fails or returns a non-success status, nil otherwise
258 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#) sendRequestscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#sendRequest().(req *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) error {
259 client := s.httpClientOrDefaultscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#httpClientOrDefault().()
260
261 resp, err := client.Doscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/HTTPClient#Do.(req)
262 if err != nil {
263 return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("sending HTTP request: %w", err)
264 }
265
266 defer func() { _ = resp.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }()
267
268 // Check response status
269 if resp.StatusCodescip-go gomod github.com/golang/go/src . `net/http`/Response#StatusCode. < 200 || resp.StatusCodescip-go gomod github.com/golang/go/src . `net/http`/Response#StatusCode. >= 300 {
270 return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%w: server returned status %d", ErrSendFailedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/ErrSendFailed., resp.StatusCodescip-go gomod github.com/golang/go/src . `net/http`/Response#StatusCode.)
271 }
272
273 // Parse response (optional, for logging)
274 s.parseResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#parseResponse().(resp)
275
276 return nil
277 }
278
279 // setAuthentication configures HTTP authentication headers on the request.
280 //
281 // Parameters:
282 // - req: the HTTP request to modify
283 // - config: the service configuration containing credentials
284 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#) setAuthenticationscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Service#setAuthentication().(req *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#, config *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#) {
285 // Add authentication - prefer Bearer token over Basic Auth
286 if config.Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#Token. != "" {
287 req.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Authorization", "Bearer "+config.Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#Token.)
288 } else if config.Userscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#User. != "" {
289 req.SetBasicAuthscip-go gomod github.com/golang/go/src . `net/http`/Request#SetBasicAuth().(config.Userscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#User., config.Passwordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/signal`/Config#Password.)
290 }
291 }