@@ -227,7 +227,7 @@ func WhatsAppLogout() error {
227227 var err error
228228
229229 // Set WhatsApp Client Presence to Unavailable
230- WhatsAppPresence (context . Background (), false )
230+ WhatsAppPresence (false )
231231
232232 // Logout WhatsApp Client and Disconnect from WebSocket
233233 err = WhatsAppClient .Logout (context .Background ())
@@ -254,15 +254,15 @@ func WhatsAppLogout() error {
254254 return errors .New ("WhatsApp Client is not Valid" )
255255}
256256
257- func WhatsAppPresence (ctx context. Context , isAvailable bool ) {
257+ func WhatsAppPresence (isAvailable bool ) {
258258 if isAvailable {
259- _ = WhatsAppClient .SendPresence (ctx , types .PresenceAvailable )
259+ _ = WhatsAppClient .SendPresence (context . Background () , types .PresenceAvailable )
260260 } else {
261- _ = WhatsAppClient .SendPresence (ctx , types .PresenceUnavailable )
261+ _ = WhatsAppClient .SendPresence (context . Background () , types .PresenceUnavailable )
262262 }
263263}
264264
265- func WhatsAppComposeStatus (ctx context. Context , rjid types.JID , isComposing bool , isAudio bool ) {
265+ func WhatsAppComposeStatus (rjid types.JID , isComposing bool , isAudio bool ) {
266266 // Set Compose Status
267267 var typeCompose types.ChatPresence
268268 if isComposing {
@@ -280,10 +280,10 @@ func WhatsAppComposeStatus(ctx context.Context, rjid types.JID, isComposing bool
280280 }
281281
282282 // Send Chat Compose Status
283- _ = WhatsAppClient .SendChatPresence (ctx , rjid , typeCompose , typeComposeMedia )
283+ _ = WhatsAppClient .SendChatPresence (context . Background () , rjid , typeCompose , typeComposeMedia )
284284}
285285
286- func WhatsAppSendGPTResponse (ctx context. Context , event * events.Message , response string ) (string , error ) {
286+ func WhatsAppSendGPTResponse (event * events.Message , response string ) (string , error ) {
287287 if WhatsAppClient != nil {
288288 var err error
289289
@@ -300,7 +300,7 @@ func WhatsAppSendGPTResponse(ctx context.Context, event *events.Message, respons
300300 }
301301
302302 // Send WhatsApp Message Proto
303- _ , err = WhatsAppClient .SendMessage (ctx , rJID , msgContent , msgExtra )
303+ _ , err = WhatsAppClient .SendMessage (context . Background () , rJID , msgContent , msgExtra )
304304 if err != nil {
305305 return "" , err
306306 }
@@ -318,7 +318,6 @@ func WhatsAppSendGPTResponse(ctx context.Context, event *events.Message, respons
318318func WhatsAppHandler (event interface {}) {
319319 switch evt := event .(type ) {
320320 case * events.Message :
321- ctx := context .Background ()
322321 realRJID := evt .Info .Chat .String ()
323322
324323 var maskRJID string
@@ -348,11 +347,11 @@ func WhatsAppHandler(event interface{}) {
348347 log .Println (log .LogLevelInfo , "Question : " + question )
349348
350349 // Set Chat Presence
351- WhatsAppPresence (ctx , true )
352- WhatsAppComposeStatus (ctx , evt .Info .Chat , true , false )
350+ WhatsAppPresence (true )
351+ WhatsAppComposeStatus (evt .Info .Chat , true , false )
353352 defer func () {
354- WhatsAppComposeStatus (ctx , evt .Info .Chat , false , false )
355- WhatsAppPresence (ctx , false )
353+ WhatsAppComposeStatus (evt .Info .Chat , false , false )
354+ WhatsAppPresence (false )
356355 }()
357356
358357 response , err := gpt .GPTResponse (question )
@@ -361,7 +360,7 @@ func WhatsAppHandler(event interface{}) {
361360 response = "Sorry, the AI can not response for this time. Please try again after a few moment 🥺"
362361 }
363362
364- _ , err = WhatsAppSendGPTResponse (ctx , evt , response )
363+ _ , err = WhatsAppSendGPTResponse (evt , response )
365364 if err != nil {
366365 log .Println (log .LogLevelError , "Failed to Send OpenAI GPT Response" )
367366 }
0 commit comments