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

Method SendSticker

handlers.go:1423–1588  ·  view source on GitHub ↗

Sends Sticker message

()

Source from the content-addressed store, hash-verified

1421 Image string
1422 Caption string
1423 Id string
1424 MimeType string
1425 ContextInfo waE2E.ContextInfo
1426 QuotedMessage *waE2E.Message `json:"QuotedMessage,omitempty"`
1427 }
1428
1429 return func(w http.ResponseWriter, r *http.Request) {
1430
1431 txtid := r.Context().Value("userinfo").(Values).Get("Id")
1432 msgid := ""
1433 var resp whatsmeow.SendResponse
1434
1435 if clientManager.GetWhatsmeowClient(txtid) == nil {
1436 s.Respond(w, r, http.StatusInternalServerError, errors.New("no session"))
1437 return
1438 }
1439
1440 decoder := json.NewDecoder(r.Body)
1441 var t imageStruct
1442 err := decoder.Decode(&t)
1443 if err != nil {
1444 s.Respond(w, r, http.StatusBadRequest, errors.New("could not decode Payload"))
1445 return
1446 }
1447
1448 if t.Phone == "" {
1449 s.Respond(w, r, http.StatusBadRequest, errors.New("missing Phone in Payload"))
1450 return
1451 }
1452
1453 if t.Image == "" {
1454 s.Respond(w, r, http.StatusBadRequest, errors.New("missing Image in Payload"))
1455 return
1456 }
1457
1458 recipient, err := validateMessageFields(r.Context(), clientManager.GetWhatsmeowClient(txtid), t.Phone, t.ContextInfo.StanzaID, t.ContextInfo.Participant)
1459 if err != nil {
1460 log.Error().Msg(fmt.Sprintf("%s", err))
1461 s.Respond(w, r, http.StatusBadRequest, err)
1462 return
1463 }
1464
1465 if t.Id == "" {
1466 msgid = clientManager.GetWhatsmeowClient(txtid).GenerateMessageID()
1467 } else {
1468 msgid = t.Id
1469 }
1470
1471 var uploaded whatsmeow.UploadResponse
1472 var filedata []byte
1473 var thumbnailBytes []byte
1474
1475 if len(t.Image) >= 10 && t.Image[0:10] == "data:image" {
1476 var dataURL, err = dataurl.DecodeString(t.Image)
1477 if err != nil {
1478 s.Respond(w, r, http.StatusBadRequest, errors.New("could not decode base64 encoded data from payload"))
1479 return
1480 } else {

Callers 1

routesMethod · 0.95

Calls 11

RespondMethod · 0.95
validateMessageFieldsFunction · 0.85
isHTTPURLFunction · 0.85
fetchURLBytesFunction · 0.85
processStickerDataFunction · 0.85
GetMethod · 0.80
GetWhatsmeowClientMethod · 0.80
StringMethod · 0.80
SendMessageMethod · 0.80

Tested by

no test coverage detected