MCPcopy Create free account
hub / github.com/asternic/wuzapi / AddUser

Method AddUser

handlers.go:5419–5601  ·  view source on GitHub ↗

Add user

()

Source from the content-addressed store, hash-verified

5417 msg := fmt.Sprintf("failed to set group topic: %v", err)
5418 s.Respond(w, r, http.StatusInternalServerError, msg)
5419 return
5420 }
5421
5422 response := map[string]interface{}{"Details": "Group Topic set successfully"}
5423 responseJson, err := json.Marshal(response)
5424
5425 if err != nil {
5426 s.Respond(w, r, http.StatusInternalServerError, err)
5427 } else {
5428 s.Respond(w, r, http.StatusOK, string(responseJson))
5429 }
5430
5431 return
5432 }
5433}
5434
5435// Leave group
5436func (s *server) GroupLeave() http.HandlerFunc {
5437
5438 type groupLeaveStruct struct {
5439 GroupJID string
5440 }
5441
5442 return func(w http.ResponseWriter, r *http.Request) {
5443
5444 txtid := r.Context().Value("userinfo").(Values).Get("Id")
5445
5446 if clientManager.GetWhatsmeowClient(txtid) == nil {
5447 s.Respond(w, r, http.StatusInternalServerError, errors.New("no session"))
5448 return
5449 }
5450
5451 decoder := json.NewDecoder(r.Body)
5452 var t groupLeaveStruct
5453 err := decoder.Decode(&t)
5454 if err != nil {
5455 s.Respond(w, r, http.StatusBadRequest, errors.New("could not decode Payload"))
5456 return
5457 }
5458
5459 group, ok := parseJID(t.GroupJID)
5460 if !ok {
5461 s.Respond(w, r, http.StatusBadRequest, errors.New("could not parse Group JID"))
5462 return
5463 }
5464
5465 err = clientManager.GetWhatsmeowClient(txtid).LeaveGroup(context.Background(), group)
5466
5467 if err != nil {
5468 log.Error().Str("error", fmt.Sprintf("%v", err)).Msg("failed to leave group")
5469 msg := fmt.Sprintf("failed to leave group: %v", err)
5470 s.Respond(w, r, http.StatusInternalServerError, msg)
5471 return
5472 }
5473
5474 response := map[string]interface{}{"Details": "Group left successfully"}
5475 responseJson, err := json.Marshal(response)
5476

Callers 1

routesMethod · 0.95

Calls 9

respondWithJSONMethod · 0.95
resolveWebhookUseProxyFunction · 0.85
encryptHMACKeyFunction · 0.85
FindFunction · 0.85
GenerateRandomIDFunction · 0.85
GetS3ManagerFunction · 0.85
proxyConfigResponseFunction · 0.85
GetMethod · 0.80
InitializeS3ClientMethod · 0.80

Tested by

no test coverage detected