├── exemple.php ├── composer.json ├── README.md └── src └── WhatsApp.php /exemple.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "raphaelvserafim/client-php-api-wa-me", 3 | "description": "Classe PHP para comunicação com api-wa.me", 4 | "type": "library", 5 | "homepage": "https://github.com/raphaelvserafim/client-php-api-wa-me", 6 | "license": "MIT", 7 | "minimum-stability": "dev", 8 | "prefer-stable": true, 9 | "autoload": { 10 | "psr-4": { 11 | "Api\\Wame\\": "src/" 12 | } 13 | }, 14 | "require": { 15 | "ext-curl": "*" 16 | }, 17 | "authors": [ 18 | { 19 | "name": "Raphael Serafim", 20 | "email": "raphaelvserafim@gmail.com" 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WhatsApp API 2 | 3 | ## About Our WhatsApp API 4 | 5 | 🔓 **Unlock the Potential of WhatsApp:** Powerful Integration with Our Unofficial API! 6 | 7 | ### Efficient Group Management on WhatsApp 8 | 9 | 📋 Our stable, though unofficial, API allows for efficient management of WhatsApp groups. Simplify administration, and easily add or remove members. 10 | 11 | ### Versatile Message Sending 12 | 13 | 💬 With our API, you can send text, audio, video, and image messages quickly and easily. Adapt to your business communication needs comprehensively. 14 | 15 | ### Receive Instant Events 16 | 17 | 🔔 Stay updated with our API, receiving real-time events when new messages are received. Stay connected and agile in responding to interactions on WhatsApp. 18 | 19 | 🔗 **Create Your Account:** Visit [https://api-wa.me/sign-up](https://api-wa.me/sign-up) to create your account and start using our API today! 20 | 21 | 🎁 **Special Discount:** Use the coupon **GIT20** and get 20% off on your first instance! 22 | 23 | ## Contact Support 24 | 25 | - **Name:** Raphael Serafim 26 | - **Email:** [support@api-wa.me](mailto:support@api-wa.me) 27 | - **Website:** [https://api-wa.me](https://api-wa.me) 28 | 29 | 30 | 31 | ## Installing via composer 32 | 33 | ``` 34 | composer require raphaelvserafim/client-php-api-wa-me 35 | ``` 36 | 37 | ### EXAMPLES 38 | 39 | 40 | ##### WHATSAPP 41 | ```php 42 | 43 | use Api\Wame\WhatsApp; 44 | 45 | include_once 'vendor/autoload.php'; 46 | 47 | $whatsapp = new WhatsApp( 48 | ["server" => "API server", 49 | "key" => "Your Key Instance"] 50 | ); 51 | ``` 52 | 53 | #### Get webhook 54 | ```php 55 | $whatsapp->constructWebhook(); 56 | $whatsapp->from->remoteJid; // number that sent message 57 | $whatsapp->from->messageType; // video | text | audio| image | sticker | document| reaction | liveLocation | 58 | $whatsapp->from->msgId; 59 | $whatsapp->from->pushName; 60 | $whatsapp->from->text; 61 | ``` 62 | 63 | #### Exemple 64 | ```php 65 | if ($whatsapp->from->messageType === "text" && $whatsapp->from->text === "Hi") { 66 | $whatsapp->sendText($whatsapp->from->remoteJid, "Hello!"); 67 | } 68 | ``` 69 | 70 | #### Get QrCode HTML 71 | ```php 72 | echo $whatsapp->connect(); 73 | ``` 74 | 75 | #### Infor Instance 76 | ```php 77 | echo $whatsapp->inforInstance(); 78 | ``` 79 | 80 | #### Update Webhook 81 | ```php 82 | $body = [ 83 | "allowWebhook" => 1, // 1=true or 0=false 84 | "webhookMessage" => "", 85 | "webhookGroup" => "", 86 | "webhookConnection" => "", 87 | "webhookQrCode" => "", 88 | "webhookMessageFromMe"=>"", 89 | "webhookHistory"=>"" 90 | ]; 91 | echo $whatsapp->updateWebhook($body); 92 | ``` 93 | 94 | #### Logout 95 | ```php 96 | echo $whatsapp->logout(); 97 | ``` 98 | 99 | ## Actions 100 | 101 | ### Get List Contacts 102 | ```php 103 | echo $whatsapp->listContacts(); 104 | ``` 105 | 106 | ### Get Profile Pic 107 | ```php 108 | echo $whatsapp->profilePic('556696852025'); 109 | ``` 110 | 111 | 112 | ### Update Profile Name 113 | ```php 114 | echo $whatsapp->updateProfileName('Raphael Serafim'); 115 | ``` 116 | 117 | ### Update Profile And Group Picture 118 | ```php 119 | $url =''; // url image 120 | echo $whatsapp->updateProfilePicture($url); 121 | ``` 122 | 123 | 124 | ## Send Message 125 | 126 | ### send Presence 127 | ```php 128 | $to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us 129 | $status = 'composing'; // unavailable | available | composing | recording | paused 130 | echo $whatsapp->sendPresence($to, $status); 131 | ``` 132 | 133 | ### send Text 134 | ```php 135 | $to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us 136 | $text = 'Hi'; 137 | echo $whatsapp->sendText($to, $text); 138 | ``` 139 | 140 | ### send Audio 141 | ```php 142 | $to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us 143 | $url = ''; // your MP3 or OGG audio URL 144 | echo $whatsapp->sendAudio($to, $url); 145 | ``` 146 | 147 | ### send Image 148 | ```php 149 | $to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us 150 | $url = ''; 151 | $caption = ''; 152 | echo $whatsapp->sendImage($to, $url); 153 | ``` 154 | 155 | ### send Video 156 | ```php 157 | $to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us 158 | $url = ''; 159 | $caption = ''; 160 | echo $whatsapp->sendVideo($to, $url); 161 | ``` 162 | 163 | 164 | 165 | ### send Document 166 | ```php 167 | $to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us 168 | $url = ''; 169 | $caption = ''; 170 | $mimetype = 'application/pdf'; // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types 171 | $fileName=''; 172 | echo $whatsapp->sendDocument($to, $url, $mimetype, $fileName); 173 | ``` 174 | 175 | 176 | ### Send Button Action 177 | ```php 178 | $body = [ 179 | 'to' => '14375223417', 180 | 'header' => [ 181 | 'title' => 'Example Title', 182 | 'hasMediaAttachment' => true, 183 | 'imageMessage' => [ 184 | 'url' => 'https://raphaelvserafim.com/og-image.png' 185 | ] 186 | ], 187 | 'text' => 'This is a test', 188 | 'footer' => 'choose an option', 189 | 'buttons' => [ 190 | [ 191 | 'type' => 'cta_copy', 192 | 'copy_code' => '1234567890', 193 | 'text' => 'Copy barcode' 194 | ], 195 | [ 196 | 'type' => 'cta_url', 197 | 'url' => 'https://api-wa.me', 198 | 'text' => 'Access the website' 199 | ], 200 | [ 201 | 'type' => 'cta_call', 202 | 'phone_number' => '+14375223417', 203 | 'text' => 'Call us' 204 | ] 205 | ] 206 | ]; 207 | echo $whatsapp->sendButton($body); 208 | ``` 209 | 210 | ### Send Button Reply 211 | ```php 212 | { 213 | "to": "14375223417", 214 | "header": { 215 | "title": "Example Header", 216 | "hasMediaAttachment": true, 217 | "imageMessage": { 218 | "url": "https://raphaelvserafim.com/og-image.png" 219 | } 220 | }, 221 | "text": "This is a test", 222 | "footer": "choose an option", 223 | "buttons": [ 224 | { 225 | "type": "quick_reply", 226 | "id": "uniqId1", 227 | "text": "Yes" 228 | }, 229 | { 230 | "type": "quick_reply", 231 | "id": "uniqId2", 232 | "text": "No" 233 | } 234 | ] 235 | } 236 | echo $whatsapp->sendButtonReply($body); 237 | ``` 238 | 239 | 240 | ### Send List 241 | ```php 242 | $body = [ 243 | "to" => "556696852025", 244 | "buttonText" => "Menu", 245 | "text" => "string", 246 | "title" => "Menu", 247 | "description" => "Description", 248 | "footer" => "footer", 249 | "sections" => [ 250 | [ 251 | "title" => "Pizza", 252 | "rows" => [ 253 | [ 254 | "title" => "Pizza 01", 255 | "description" => "Example pizza 01", 256 | "rowId" => "1" 257 | ] 258 | ] 259 | ] 260 | ] 261 | ]; 262 | echo $whatsapp->sendList($body); 263 | ``` 264 | 265 | 266 | ### send Contact 267 | ```php 268 | $to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us 269 | $name = 'CACHE SISTEMAS'; 270 | $number = '+556696883327'; 271 | echo $whatsapp->sendContact($to, $name, $number); 272 | ``` 273 | 274 | ### send Location 275 | ```php 276 | $to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us 277 | $lat = 37.7749; 278 | $lon = -122.4194; 279 | $address = '123 Main St, San Francisco, CA'; 280 | echo $whatsapp->sendLocation($to, $lat, $lon, $address); 281 | ``` 282 | 283 | ### send Reaction 284 | ```php 285 | $to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us 286 | $text = '😘'; 287 | $msgId = ''; 288 | echo $whatsapp->sendReaction($to, $text, $msgId); 289 | ``` 290 | 291 | 292 | ## Group 293 | 294 | ### Get list Group 295 | ```php 296 | echo $whatsapp->listGroup(); 297 | ``` 298 | 299 | ### Get infor Group 300 | ```php 301 | $group_id = '123456789@g.us'; 302 | echo $whatsapp->inforGroup($group_id); 303 | ``` 304 | 305 | 306 | ### Get Invite Code Group 307 | ```php 308 | $group_id = '123456789@g.us'; 309 | echo $whatsapp->groupInviteCode($group_id); 310 | ``` 311 | 312 | ### create Group 313 | ```php 314 | $name = 'API PHP WhatsApp'; 315 | $participants = ['556696852025']; 316 | echo $whatsapp->createGroup($name, $participants); 317 | ``` 318 | 319 | 320 | ### add Participants Group 321 | ```php 322 | $group_id = '123456789@g.us'; 323 | $participants = ['556696852025']; 324 | echo $whatsapp->addParticipantsGroup($group_id, $participants); 325 | ``` 326 | 327 | 328 | ### Promote Participants Group Admin 329 | ```php 330 | $group_id = '123456789@g.us'; 331 | $participants = ['556696852025']; 332 | $action = "promote"; // demote 333 | echo $whatsapp->promoteParticipantsGroup($group_id, $participants, $action); 334 | ``` 335 | 336 | ### Remove Participants Group 337 | ```php 338 | $group_id = '123456789@g.us'; 339 | $participants = ['556696852025']; 340 | echo $whatsapp->removeParticipantsGroup($group_id, $participants); 341 | ``` 342 | 343 | ### Leave Group 344 | ```php 345 | $group_id = '123456789@g.us'; 346 | echo $whatsapp->leaveGroup($group_id); 347 | ``` 348 | 349 | 350 | -------------------------------------------------------------------------------- /src/WhatsApp.php: -------------------------------------------------------------------------------- 1 | server = $data["server"]; 21 | } 22 | if (isset($data["key"])) { 23 | $this->key = $data["key"]; 24 | } 25 | } 26 | 27 | private function request() 28 | { 29 | try { 30 | $this->header[] = 'Content-Type: application/json'; 31 | $ch = curl_init(); 32 | curl_setopt($ch, CURLOPT_URL, $this->server . $this->parth); 33 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 34 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->method); 35 | if ($this->method === 'POST' || $this->method === 'PUT') { 36 | curl_setopt($ch, CURLOPT_POST, true); 37 | curl_setopt($ch, CURLOPT_POSTFIELDS, $this->body); 38 | } 39 | curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header); 40 | $result = curl_exec($ch); 41 | if (curl_errno($ch)) { 42 | $errorMessage = curl_error($ch); 43 | curl_close($ch); 44 | throw new \RuntimeException("cURL Error: $errorMessage"); 45 | } 46 | curl_close($ch); 47 | return $result; 48 | } catch (\Throwable $th) { 49 | return null; 50 | } 51 | } 52 | 53 | /** 54 | * Obtém o código QR em HTML para a instância atual. 55 | * 56 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 57 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 58 | */ 59 | public function connect() 60 | { 61 | // Define o caminho, método e corpo da requisição para obter o código QR em HTML. 62 | $this->parth = "/{$this->key}/instance"; 63 | $this->method = "POST"; 64 | // Executa a requisição e retorna o resultado. 65 | return $this->request(); 66 | } 67 | 68 | public function updateSaveMediaMarkMessageRead(bool $markMessageRead, bool $saveMedia) 69 | { 70 | $markMessageReadValue = json_encode($markMessageRead); 71 | $saveMediaValue = json_encode($saveMedia); 72 | $this->parth = "/{$this->key}/instance/?markMessageRead={$markMessageReadValue}&saveMedia={$saveMediaValue}"; 73 | $this->method = "PATCH"; 74 | return $this->request(); 75 | } 76 | 77 | /** 78 | * Obtém informações sobre a instância atual. 79 | * 80 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 81 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 82 | */ 83 | public function inforInstance() 84 | { 85 | // Define o caminho, método e corpo da requisição para obter informações sobre a instância. 86 | $this->parth = "/{$this->key}/instance"; 87 | $this->method = "GET"; 88 | // Executa a requisição e retorna o resultado. 89 | return $this->request(); 90 | } 91 | 92 | 93 | /** 94 | * Atualiza o webhook para a instância atual. 95 | * 96 | * @param mixed $body Os dados a serem enviados no corpo da requisição. 97 | * 98 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 99 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 100 | */ 101 | public function updateWebhook($body) 102 | { 103 | // Define o caminho, método e corpo da requisição para atualizar o webhook. 104 | $this->parth = "/{$this->key}/instance"; 105 | $this->method = "PUT"; 106 | $this->body = json_encode($body); 107 | // Executa a requisição e retorna o resultado. 108 | return $this->request(); 109 | } 110 | 111 | /** 112 | * Faz logout da instância atual. 113 | * 114 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 115 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 116 | */ 117 | public function logout() 118 | { 119 | // Define o caminho, método e corpo da requisição para efetuar o logout. 120 | $this->parth = "/{$this->key}/instance"; 121 | $this->method = "DELETE"; 122 | 123 | // Executa a requisição e retorna o resultado. 124 | return $this->request(); 125 | } 126 | 127 | 128 | /** 129 | * Lista todos os contatos associados à instância atual. 130 | * 131 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 132 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 133 | */ 134 | public function listContacts() 135 | { 136 | // Define o caminho, método e corpo da requisição para listar os contatos. 137 | $this->parth = "/{$this->key}/contacts"; 138 | $this->method = "GET"; 139 | // Executa a requisição e retorna o resultado. 140 | return $this->request(); 141 | } 142 | 143 | /** 144 | * Obtém a imagem do perfil de um contato específico. 145 | * 146 | * @param string $to O identificador do contato para o qual se deseja obter a imagem do perfil. 147 | * 148 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 149 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 150 | */ 151 | public function profilePic(string $to) 152 | { 153 | // Define o caminho, método e corpo da requisição para obter a imagem do perfil. 154 | $this->parth = "/{$this->key}/contacts/{$to}"; 155 | $this->method = "GET"; 156 | // Executa a requisição e retorna o resultado. 157 | return $this->request(); 158 | } 159 | 160 | /** 161 | * Atualiza o nome do perfil. 162 | * 163 | * @param string $name O novo nome para o perfil. 164 | * 165 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 166 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 167 | */ 168 | public function updateProfileName(string $name) 169 | { 170 | // Define o caminho, método e corpo da requisição para atualizar o nome do perfil. 171 | // $this->parth = "/actions/updateProfileName?key={$this->key}"; 172 | // $this->method = "POST"; 173 | // $this->body = json_encode(["name" => $name]); 174 | // // Executa a requisição e retorna o resultado. 175 | // return $this->request(); 176 | } 177 | 178 | 179 | /** 180 | * Atualiza a imagem do perfil. 181 | * 182 | * @param mixed $to O destino da atualização da imagem do perfil. 183 | * @param string $url A URL da nova imagem do perfil. 184 | * 185 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 186 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 187 | */ 188 | public function updateProfilePicture(string $url) 189 | { 190 | // Define o caminho, método e corpo da requisição para atualizar a imagem do perfil. 191 | $this->parth = "/{$this->key}/actions/picture"; 192 | $this->method = "PUT"; 193 | $this->body = json_encode(["url" => $url]); 194 | // Executa a requisição e retorna o resultado. 195 | return $this->request(); 196 | } 197 | 198 | /** 199 | * Envia um recibo de leitura para uma mensagem específica. 200 | * 201 | * @param string $to O identificador do destinatário. 202 | * @param string $MsgId O identificador da mensagem. 203 | * 204 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 205 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 206 | */ 207 | public function readReceipt(string $to, string $MsgId) 208 | { 209 | // Define o corpo da requisição para enviar um recibo de leitura. 210 | // $body = ["to" => $to, "idMsg" => $MsgId]; 211 | // $this->parth = "/actions/readReceipt?key={$this->key}"; 212 | // $this->method = "POST"; 213 | // $this->body = json_encode($body); 214 | 215 | // // Executa a requisição e retorna o resultado. 216 | // return $this->request(); 217 | } 218 | 219 | 220 | /** 221 | * Baixa um arquivo de mídia associado a uma mensagem. 222 | * 223 | * @param mixed $body Os dados a serem enviados no corpo da requisição. 224 | * 225 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 226 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 227 | */ 228 | public function downloadMediaMessage($type, $body) 229 | { 230 | // Define o caminho, método e corpo da requisição para baixar um arquivo de mídia. 231 | $this->parth = "/{$this->key}/actions/download/media?type=" . $type; 232 | $this->method = "POST"; 233 | $this->body = json_encode($body); 234 | // Executa a requisição e retorna o resultado. 235 | return $this->request(); 236 | } 237 | 238 | 239 | /** 240 | * Envia um status de presença para um destinatário. 241 | * 242 | * @param string $to O identificador do destinatário. 243 | * @param string $status O status de presença a ser enviado. 244 | * 245 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 246 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 247 | */ 248 | public function sendPresence(string $to, string $status) 249 | { 250 | // Define o corpo da requisição para enviar um status de presença. 251 | $this->parth = "/{$this->key}/message/presence"; 252 | $this->method = "POST"; 253 | $this->body = json_encode([ 254 | "to" => $to, 255 | "status" => $status 256 | ]); 257 | // Executa a requisição e retorna o resultado. 258 | return $this->request(); 259 | } 260 | 261 | /** 262 | * Envia uma mensagem de texto para um destinatário. 263 | * 264 | * @param string $to O identificador do destinatário. 265 | * @param string $text O texto da mensagem a ser enviado. 266 | * 267 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 268 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 269 | */ 270 | public function sendText(string $to, string $text) 271 | { 272 | // Define o corpo da requisição para enviar uma mensagem de texto. 273 | $this->parth = "/{$this->key}/message/text"; 274 | $this->method = "POST"; 275 | $this->body = json_encode([ 276 | "to" => $to, 277 | "text" => $text 278 | ]); 279 | // Executa a requisição e retorna o resultado. 280 | return $this->request(); 281 | } 282 | 283 | /** 284 | * Envia uma mensagem de áudio para um destinatário. 285 | * 286 | * @param string $to O identificador do destinatário. 287 | * @param string $url A URL do arquivo de áudio. 288 | * @param bool $ptt Indica se o áudio deve ser reproduzido como push-to-talk (PTT). 289 | * 290 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 291 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 292 | */ 293 | public function sendAudio(string $to, string $url, bool $ptt = true) 294 | { 295 | // Define o corpo da requisição para enviar uma mensagem de áudio. 296 | $this->parth = "/{$this->key}/message/audio"; 297 | $this->method = "POST"; 298 | $this->body = json_encode([ 299 | "to" => $to, 300 | "url" => $url 301 | ]); 302 | // Executa a requisição e retorna o resultado. 303 | return $this->request(); 304 | } 305 | 306 | 307 | /** 308 | * Envia uma mensagem de mídia (base64) para um destinatário. 309 | * 310 | * @param string $to O identificador do destinatário. 311 | * @param string $base64String A string base64 que representa a mídia. 312 | * @param string $type O tipo de mídia (por exemplo, imagem, vídeo, áudio). 313 | * @param string $caption Uma legenda para a mídia. 314 | * 315 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 316 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 317 | */ 318 | public function sendMediaBase64(string $to, string $base64String, string $type, string $caption) 319 | { 320 | // Define o caminho, método e corpo da requisição para enviar uma mensagem de mídia (base64). 321 | $this->parth = "/message/sendMediaBase64?key={$this->key}"; 322 | $this->method = "POST"; 323 | $this->body = json_encode([ 324 | "data" => [ 325 | "to" => $to, 326 | "stringBase64" => $base64String, 327 | "type" => $type, 328 | "caption" => $caption 329 | ] 330 | ]); 331 | 332 | // Executa a requisição e retorna o resultado. 333 | return $this->request(); 334 | } 335 | 336 | /** 337 | * Envia uma mensagem de pesquisa para um destinatário. 338 | * 339 | * @param string $to O identificador do destinatário. 340 | * @param string $name O nome da pesquisa. 341 | * @param array $options Um array contendo as opções da pesquisa. 342 | * 343 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 344 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 345 | */ 346 | public function sendSurvey(string $to, string $name, array $options) 347 | { 348 | // Define o caminho, método e corpo da requisição para enviar uma mensagem de pesquisa. 349 | $this->parth = "/{$this->key}/message/survey"; 350 | $this->method = "POST"; 351 | $this->body = json_encode([ 352 | "to" => $to, 353 | "name" => $name, 354 | "options" => $options 355 | ]); 356 | // Executa a requisição e retorna o resultado. 357 | return $this->request(); 358 | } 359 | 360 | 361 | 362 | /** 363 | * Responde a uma mensagem específica. 364 | * 365 | * @param string $to O identificador do destinatário. 366 | * @param string $text O texto da resposta. 367 | * @param string $messageId O identificador da mensagem à qual está respondendo. 368 | * @param array $msgContent Um array contendo o conteúdo da mensagem (se necessário). 369 | * 370 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 371 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 372 | */ 373 | public function replyToMessage(string $to, string $text, string $messageId, array $msgContent = []) 374 | { 375 | // // Define o caminho, método e corpo da requisição para responder a uma mensagem. 376 | // $this->parth = "/message/replymessage?key={$this->key}"; 377 | // $this->method = "POST"; 378 | // $this->body = json_encode([ 379 | // "messageData" => [ 380 | // "to" => $to, 381 | // "text" => $text, 382 | // "messageId" => $messageId, 383 | // "msgContent" => $msgContent 384 | // ] 385 | // ]); 386 | // // Executa a requisição e retorna o resultado. 387 | // return $this->request(); 388 | } 389 | 390 | 391 | /** 392 | * Envia uma mensagem de texto com menções para um grupo específico. 393 | * 394 | * @param string $groupId O identificador do grupo. 395 | * @param string $text O texto da mensagem com menções. 396 | * @param array $mentions Um array contendo os identificadores das menções. 397 | * 398 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 399 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 400 | */ 401 | public function sendTextWithMentions(string $groupId, string $text, array $mentions) 402 | { 403 | // Define o caminho, método e corpo da requisição para enviar uma mensagem de texto com menções. 404 | // $this->parth = "/message/textMentions?key={$this->key}"; 405 | // $this->method = "POST"; 406 | // $this->body = json_encode([ 407 | // "data" => [ 408 | // "group_id" => $groupId, 409 | // "text" => $text, 410 | // "mentions" => $mentions 411 | // ] 412 | // ]); 413 | 414 | // // Executa a requisição e retorna o resultado. 415 | // return $this->request(); 416 | } 417 | 418 | 419 | /** 420 | * Envia uma mensagem de mídia para um destinatário. 421 | * 422 | * @param string $to O identificador do destinatário. 423 | * @param string $url A URL do arquivo de mídia. 424 | * @param string $type O tipo de mídia (por exemplo, "image", "video"). 425 | * @param string $caption A legenda da mídia. 426 | * @param string $mimeType O tipo MIME do arquivo de mídia. 427 | * @param bool $ptt Indica se o áudio deve ser reproduzido como push-to-talk (PTT). 428 | * 429 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 430 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 431 | */ 432 | public function sendMedia(string $to, string $url, string $type, string $caption, string $mimeType = '', bool $ptt = false) 433 | { 434 | // Define o corpo da requisição para enviar uma mensagem de mídia. 435 | // $this->parth = "/message/media?key={$this->key}"; 436 | // $this->method = "POST"; 437 | // $this->body = json_encode([ 438 | // "data" => [ 439 | // "to" => $to, 440 | // "url" => $url, 441 | // "type" => $type, 442 | // "caption" => $caption, 443 | // "mimeType" => $mimeType, 444 | // "ptt" => $ptt 445 | // ] 446 | // ]); 447 | // Executa a requisição e retorna o resultado. 448 | //return $this->request(); 449 | } 450 | 451 | 452 | public function sendImage(string $to, string $url, string $caption) 453 | { 454 | // Define o corpo da requisição para enviar uma mensagem de mídia. 455 | $this->parth = "/{$this->key}/message/image"; 456 | $this->method = "POST"; 457 | $this->body = json_encode([ 458 | "to" => $to, 459 | "url" => $url, 460 | "caption" => $caption, 461 | ]); 462 | return $this->request(); 463 | } 464 | 465 | public function sendVideo(string $to, string $url, string $caption) 466 | { 467 | // Define o corpo da requisição para enviar uma mensagem de mídia. 468 | $this->parth = "/{$this->key}/message/video"; 469 | $this->method = "POST"; 470 | $this->body = json_encode([ 471 | "to" => $to, 472 | "url" => $url, 473 | "caption" => $caption, 474 | ]); 475 | return $this->request(); 476 | } 477 | 478 | public function sendDocument(string $to, string $url, string $caption, string $mimetype, $fileName) 479 | { 480 | // Define o corpo da requisição para enviar uma mensagem de mídia. 481 | $this->parth = "/{$this->key}/message/document"; 482 | $this->method = "POST"; 483 | $this->body = json_encode([ 484 | "to" => $to, 485 | "url" => $url, 486 | "caption" => $caption, 487 | "mimetype" => $mimetype, 488 | "fileName" => $fileName, 489 | ]); 490 | return $this->request(); 491 | } 492 | 493 | 494 | /** 495 | * Envia uma mensagem com botões para um destinatário. 496 | * 497 | * @param mixed $body Os dados a serem enviados no corpo da requisição. 498 | * 499 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 500 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 501 | */ 502 | public function sendButton($body) 503 | { 504 | 505 | // Define o corpo da requisição para enviar uma mensagem com botões. 506 | $this->parth = "/{$this->key}/message/button_action"; 507 | $this->method = "POST"; 508 | $this->body = json_encode($body); 509 | // Executa a requisição e retorna o resultado. 510 | return $this->request(); 511 | } 512 | 513 | 514 | /** 515 | * Envia uma resposta a um botão pressionado por um destinatário. 516 | * 517 | * @param mixed $body Os dados a serem enviados no corpo da requisição. 518 | * 519 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 520 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 521 | */ 522 | public function sendButtonReply($body) 523 | { 524 | 525 | // Define o corpo da requisição para enviar uma mensagem com botões. 526 | $this->parth = "/{$this->key}/message/button_reply"; 527 | $this->method = "POST"; 528 | $this->body = json_encode($body); 529 | // Executa a requisição e retorna o resultado. 530 | return $this->request(); 531 | } 532 | 533 | 534 | 535 | /** 536 | * Envia uma mensagem com botões de modelo para um destinatário. 537 | * 538 | * @param mixed $body Os dados a serem enviados no corpo da requisição. 539 | * 540 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 541 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 542 | */ 543 | public function sendTemplateButtons($body) 544 | { 545 | // Define o corpo da requisição para enviar uma mensagem com botões de modelo. 546 | // $this->parth = "/message/templateButtons?key={$this->key}"; 547 | // $this->method = "POST"; 548 | // $this->body = json_encode($body); 549 | 550 | // // Executa a requisição e retorna o resultado. 551 | // return $this->request(); 552 | } 553 | 554 | /** 555 | * Envia uma lista para um destinatário. 556 | * 557 | * @param mixed $body Os dados a serem enviados no corpo da requisição. 558 | * 559 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 560 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 561 | */ 562 | public function sendList($body) 563 | { 564 | // Define o corpo da requisição para enviar uma lista. 565 | $this->parth = "/{$this->key}/message/list"; 566 | $this->method = "POST"; 567 | $this->body = json_encode($body); 568 | // Executa a requisição e retorna o resultado. 569 | return $this->request(); 570 | } 571 | 572 | /** 573 | * Envia um cartão de contato para um destinatário. 574 | * 575 | * @param string $to O identificador do destinatário. 576 | * @param string $name O nome do contato. 577 | * @param string $number O número do contato. 578 | * 579 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 580 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 581 | */ 582 | public function sendContact(string $to, string $name, string $number) 583 | { 584 | // Define o corpo da requisição para enviar um cartão de contato. 585 | $this->parth = "/{$this->key}/message/contact"; 586 | $this->method = "POST"; 587 | $this->body = json_encode([ 588 | "to" => $to, 589 | "contact" => [ 590 | "fullName" => $name, 591 | "organization" => "", 592 | "phoneNumber" => $number 593 | ] 594 | ]); 595 | // Executa a requisição e retorna o resultado. 596 | return $this->request(); 597 | } 598 | 599 | /** 600 | * Envia uma localização para um destinatário. 601 | * 602 | * @param string $to O identificador do destinatário. 603 | * @param float $lat A latitude da localização. 604 | * @param float $lon A longitude da localização. 605 | * @param string $address O endereço da localização. 606 | * 607 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 608 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 609 | */ 610 | public function sendLocation(string $to, float $lat, float $lon, string $address) 611 | { 612 | // Define o corpo da requisição para enviar uma localização. 613 | $this->parth = "/{$this->key}/message/location"; 614 | $this->method = "POST"; 615 | $this->body = json_encode([ 616 | "to" => $to, 617 | "location" => [ 618 | "latitude" => $lat, 619 | "longitude" => $lon, 620 | "address" => $address 621 | ] 622 | ]); 623 | // Executa a requisição e retorna o resultado. 624 | return $this->request(); 625 | } 626 | 627 | 628 | /** 629 | * Envia uma reação a uma mensagem específica. 630 | * 631 | * @param string $to O identificador do destinatário. 632 | * @param string $text O texto da reação. 633 | * @param string $MsgId O identificador da mensagem à qual a reação está associada. 634 | * 635 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 636 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 637 | */ 638 | public function sendReaction(string $to, string $text, string $msgId) 639 | { 640 | // Define o corpo da requisição para enviar uma reação. 641 | $this->parth = "/{$this->key}/message/reaction"; 642 | $this->method = "POST"; 643 | $this->body = json_encode([ 644 | "to" => $to, 645 | "text" => $text, 646 | "msgId" => $msgId 647 | ]); 648 | // Executa a requisição e retorna o resultado. 649 | return $this->request(); 650 | } 651 | 652 | 653 | /** 654 | * Lista todos os grupos associados à instância atual. 655 | * 656 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 657 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 658 | */ 659 | public function listGroup() 660 | { 661 | // Define o caminho, método e corpo da requisição para listar todos os grupos. 662 | $this->parth = "/{$this->key}/groups"; 663 | $this->method = "GET"; 664 | // Executa a requisição e retorna o resultado. 665 | return $this->request(); 666 | } 667 | 668 | /** 669 | * Obtém informações sobre um grupo específico. 670 | * 671 | * @param string $group_id O identificador do grupo. 672 | * 673 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 674 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 675 | */ 676 | public function inforGroup(string $group_id) 677 | { 678 | // Define o caminho, método e corpo da requisição para obter informações sobre um grupo. 679 | $this->parth = "/{$this->key}/groups/{$group_id}"; 680 | $this->method = "GET"; 681 | // Executa a requisição e retorna o resultado. 682 | return $this->request(); 683 | } 684 | 685 | /** 686 | * Obtém o código de convite de um grupo específico. 687 | * 688 | * @param string $group_id O identificador do grupo. 689 | * 690 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 691 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 692 | */ 693 | public function groupInviteCode(string $group_id) 694 | { 695 | // Define o caminho, método e corpo da requisição para obter o código de convite de um grupo. 696 | $this->parth = "/{$this->key}/groups/{$group_id}/invite"; 697 | $this->method = "GET"; 698 | // Executa a requisição e retorna o resultado. 699 | return $this->request(); 700 | } 701 | 702 | /** 703 | * Cria um novo grupo. 704 | * 705 | * @param string $name O nome do grupo. 706 | * @param array $participants Um array contendo os identificadores dos participantes do grupo. 707 | * 708 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 709 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 710 | */ 711 | public function createGroup(string $name, array $participants) 712 | { 713 | // Define o corpo da requisição para criar um novo grupo. 714 | $this->parth = "/{$this->key}/groups"; 715 | $this->method = "POST"; 716 | $this->body = json_encode([ 717 | "name" => $name, 718 | "participants" => $participants 719 | ]); 720 | // Executa a requisição e retorna o resultado. 721 | return $this->request(); 722 | } 723 | 724 | /** 725 | * Adiciona participantes a um grupo existente. 726 | * 727 | * @param string $group_id O identificador do grupo. 728 | * @param array $participants Um array contendo os identificadores dos participantes a serem adicionados. 729 | * 730 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 731 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 732 | */ 733 | public function addParticipantsGroup(string $group_id, array $participants) 734 | { 735 | // Define o corpo da requisição para adicionar participantes a um grupo existente. 736 | $this->parth = "/{$this->key}/groups/{$group_id}/participants"; 737 | $this->method = "POST"; 738 | $this->body = json_encode([ 739 | "participants" => $participants 740 | ]); 741 | // Executa a requisição e retorna o resultado. 742 | return $this->request(); 743 | } 744 | 745 | /** 746 | * Remove participantes de um grupo existente. 747 | * 748 | * @param string $group_id O identificador do grupo. 749 | * @param array $participants Um array contendo os identificadores dos participantes a serem removidos. 750 | * 751 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 752 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 753 | */ 754 | public function removeParticipantsGroup(string $group_id, array $participants) 755 | { 756 | // Define o corpo da requisição para remover participantes de um grupo existente. 757 | $this->parth = "/{$this->key}/groups/{$group_id}/participants"; 758 | $this->method = "DELETE"; 759 | $this->body = json_encode([ 760 | "participants" => $participants 761 | ]); 762 | // Executa a requisição e retorna o resultado. 763 | return $this->request(); 764 | } 765 | 766 | /** 767 | * Deixa um grupo existente. 768 | * 769 | * @param string $group_id O identificador do grupo. 770 | * 771 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 772 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 773 | */ 774 | public function leaveGroup(string $group_id) 775 | { 776 | // Define o caminho, método e corpo da requisição para deixar um grupo existente. 777 | $this->parth = "/{$this->key}/groups/{$group_id}"; 778 | $this->method = "DELETE"; 779 | // Executa a requisição e retorna o resultado. 780 | return $this->request(); 781 | } 782 | 783 | /** 784 | * Promove participantes a administradores em um grupo existente. 785 | * 786 | * @param string $group_id O identificador do grupo. 787 | * @param array $participants Um array contendo os identificadores dos participantes a serem promovidos. 788 | * 789 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 790 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 791 | */ 792 | public function promoteParticipantsGroup(string $group_id, array $participants, string $action) 793 | { 794 | // Define o corpo da requisição para promover participantes a administradores em um grupo existente. 795 | $this->parth = "/{$this->key}/groups/{$group_id}/role?action={$action}"; 796 | $this->method = "POST"; 797 | $this->body = json_encode(["participants" => $participants]); 798 | // Executa a requisição e retorna o resultado. 799 | return $this->request(); 800 | } 801 | 802 | /** 803 | * Define quem pode enviar mensagens em um grupo específico. 804 | * 805 | * @param string $group_id O identificador do grupo. 806 | * @param bool $allow Indica se apenas administradores podem enviar mensagens no grupo. 807 | * 808 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 809 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 810 | */ 811 | public function setWhoCanSendMessageGroup(string $group_id, bool $allow) 812 | { 813 | // Define o corpo da requisição para definir quem pode enviar mensagens em um grupo específico. 814 | // $this->parth = "/group/setWhoCanSendMessage?key={$this->key}&group_id={$group_id}&allowOnlyAdmins=" . $allow; 815 | // $this->method = "POST"; 816 | // // Executa a requisição e retorna o resultado. 817 | // return $this->request(); 818 | } 819 | 820 | /** 821 | * Define quem pode alterar configurações em um grupo específico. 822 | * 823 | * @param string $group_id O identificador do grupo. 824 | * @param bool $allow Indica se apenas administradores podem alterar configurações no grupo. 825 | * 826 | * @return mixed A resposta da requisição ou uma mensagem de erro em caso de falha. 827 | * @throws \RuntimeException Se ocorrer um erro durante a requisição cURL. 828 | */ 829 | public function setWhoCanChangeSettingsGroup(string $group_id, bool $allow) 830 | { 831 | // Define o corpo da requisição para definir quem pode alterar configurações em um grupo específico. 832 | // $this->parth = "/group/setWhoCanChangeSettings?key={$this->key}&group_id={$group_id}&allowOnlyAdmins=" . $allow; 833 | // $this->method = "POST"; 834 | // // Executa a requisição e retorna o resultado. 835 | // return $this->request(); 836 | } 837 | 838 | 839 | 840 | 841 | public function constructWebhook() 842 | { 843 | 844 | $isMidia = false; 845 | 846 | $data = json_decode(file_get_contents('php://input'), true); 847 | 848 | if (!empty($data)) { 849 | 850 | $this->from = new stdClass(); 851 | 852 | if (isset($data["data"]["key"]["remoteJid"])) { 853 | $this->from->remoteJid = preg_replace("/[^0-9]/", "", $data["data"]["key"]["remoteJid"]); 854 | } 855 | 856 | if (isset($data["data"]["key"]["id"])) { 857 | $this->from->msgId = $data["data"]["key"]["id"] ?? null; 858 | } 859 | 860 | if (isset($data["data"]["push_name"])) { 861 | $this->from->pushName = $data["data"]["push_name"] ?? null; 862 | } 863 | 864 | if (isset($data["data"]["messageType"])) { 865 | $this->from->messageType = $data["data"]["messageType"] ?? "unknown"; 866 | } 867 | 868 | if (isset($data["data"]["msgContent"]["conversation"])) { 869 | $this->from->messageType = "text"; 870 | $this->from->text = $data["data"]["msgContent"]["conversation"]; 871 | } 872 | 873 | if (isset($data["data"]["msgContent"]["extendedTextMessage"]["text"])) { 874 | $this->from->messageType = "text"; 875 | $this->from->text = $data["data"]["msgContent"]["extendedTextMessage"]["text"]; 876 | } 877 | 878 | if (isset($data["data"]["msgContent"]["buttonsResponseMessage"])) { 879 | $this->from->messageType = "button"; 880 | $this->from->selectedId = $data["data"]["msgContent"]["buttonsResponseMessage"]["selectedButtonId"]; 881 | } 882 | 883 | 884 | if (isset($data["data"]["msgContent"]["listResponseMessage"])) { 885 | $this->from->messageType = "list"; 886 | $this->from->selectedId = $data["data"]["msgContent"]["listResponseMessage"]["singleSelectReply"]["selectedRowId"]; 887 | $this->from->title = $data["data"]["msgContent"]["listResponseMessage"]["title"]; 888 | } 889 | 890 | if ($this->from->messageType == "messageContextInfo") { 891 | $this->from->messageType = "list"; 892 | if (isset($data["data"]["msgContent"]["listResponseMessage"]["singleSelectReply"]["selectedRowId"])) { 893 | $this->from->selectedId = $data["data"]["msgContent"]["listResponseMessage"]["singleSelectReply"]["selectedRowId"]; 894 | } 895 | if (isset($data["data"]["msgContent"]["listResponseMessage"]["title"])) { 896 | $this->from->text = $data["data"]["msgContent"]["listResponseMessage"]["title"]; 897 | } 898 | } 899 | 900 | if (isset($data["data"]["msgContent"]["reactionMessage"])) { 901 | $this->from->messageType = "reaction"; 902 | $this->from->text = $data["data"]["msgContent"]["reactionMessage"]["text"]; 903 | } 904 | 905 | if ($this->from->latitude === "locationMessage") { 906 | $this->from->messageType = "location"; 907 | $this->from->latitude = $data["data"]["msgContent"]["locationMessage"]["degreesLatitude"]; 908 | $this->from->longitude = $data["data"]["msgContent"]["locationMessage"]["degreesLongitude"]; 909 | $this->from->thumbnail = "data:image/jpeg;base64," . $data["data"]["msgContent"]["locationMessage"]["jpegThumbnail"]; 910 | } 911 | 912 | if ($this->from->messageType === "liveLocationMessage") { 913 | $this->from->messageType = "liveLocation"; 914 | $this->from->latitude = $data["data"]["msgContent"]["liveLocationMessage"]["degreesLatitude"]; 915 | $this->from->longitude = $data["data"]["msgContent"]["liveLocationMessage"]["degreesLongitude"]; 916 | $this->from->thumbnail = "data:image/jpeg;base64," . $data["data"]["msgContent"]["liveLocationMessage"]["jpegThumbnail"]; 917 | } 918 | 919 | if ($this->from->messageType === "templateButtonReplyMessage") { 920 | $this->from->messageType = "button"; 921 | $this->from->selectedId = $data["data"]["msgContent"]["templateButtonReplyMessage"]["selectedIndex"]; 922 | } 923 | 924 | if ($this->from->messageType === "audioMessage") { 925 | $this->from->messageType = "audio"; 926 | $isMidia = true; 927 | } 928 | if ($this->from->messageType === "imageMessage") { 929 | $this->from->messageType = "image"; 930 | $isMidia = true; 931 | } 932 | 933 | if ($this->from->messageType === "stickerMessage") { 934 | $this->from->messageType = "sticker"; 935 | $isMidia = true; 936 | } 937 | if ($this->from->messageType === "videoMessage") { 938 | $this->from->messageType = "video"; 939 | $isMidia = true; 940 | } 941 | 942 | if ($this->from->messageType === "documentMessage") { 943 | $this->from->messageType = "document"; 944 | $isMidia = true; 945 | } 946 | 947 | if ($this->from->messageType === "contactMessage") { 948 | $this->from->messageType = "contact"; 949 | $displayName = $data["data"]["msgContent"]["contactMessage"]["displayName"] ?? ""; 950 | $vcard = explode("\n", $data["data"]["msgContent"]["contactMessage"]["vcard"]); 951 | $c_b = explode(":", $vcard[4]); 952 | $contact = new stdClass(); 953 | $contact->name = $displayName; 954 | $contact->number = $c_b[1] ?? ""; 955 | $this->from->contact[] = $contact; 956 | } 957 | 958 | if ($this->from->messageType === "contactsArrayMessage") { 959 | $this->from->messageType = "contact"; 960 | for ($i = 0; sizeof($data["data"]["msgContent"]["contactsArrayMessage"]["contacts"]) > $i; $i++) { 961 | $displayName = $data["data"]["msgContent"]["contactsArrayMessage"]["contacts"][$i]["displayName"]; 962 | $vcard = explode("\n", $data["data"]["msgContent"]["contactsArrayMessage"]["contacts"][$i]["vcard"]); 963 | $c_b = explode(":", $vcard[4]); 964 | $contact = new stdClass(); 965 | $contact->name = $displayName; 966 | $contact->number = $c_b[1] ?? ""; 967 | $this->from->contact[] = $contact; 968 | } 969 | } 970 | 971 | if ($isMidia) { 972 | 973 | if (isset($data["data"]["msgContent"][$data["data"]["messageType"]]["mimetype"])) { 974 | $this->from->mimetype = $data["data"]["msgContent"][$data["data"]["messageType"]]["mimetype"]; 975 | } 976 | if (!empty($data["data"]["msgContent"][$data["data"]["messageType"]]["jpegThumbnail"])) { 977 | $this->from->thumbnail = "data:image/jpeg;base64," . $data["data"]["msgContent"][$data["data"]["messageType"]]["jpegThumbnail"]; 978 | } 979 | 980 | $this->from->messageKeys = [ 981 | "messageKeys" => [ 982 | "mediaKey" => $data["data"]["msgContent"][$data["data"]["messageType"]]["mediaKey"], 983 | "directPath" => $data["data"]["msgContent"][$data["data"]["messageType"]]["directPath"], 984 | "url" => $data["data"]["msgContent"][$data["data"]["messageType"]]["url"], 985 | "messageType" => $this->from->messageType 986 | ] 987 | ]; 988 | 989 | $this->from->mediaBase64 = $data["data"]["fileBase64"]; 990 | $this->from->mediaURL = $data["data"]["urlMedia"]; 991 | 992 | if (isset($data["data"]["msgContent"][$data["data"]["messageType"]]["title"])) { 993 | $this->from->title = $data["data"]["msgContent"][$data["data"]["messageType"]]["title"]; 994 | } 995 | 996 | if (isset($data["data"]["msgContent"][$data["data"]["messageType"]]["fileName"])) { 997 | $this->from->caption = $data["data"]["msgContent"][$data["data"]["messageType"]]["fileName"]; 998 | } 999 | 1000 | if (isset($data["data"]["msgContent"][$data["data"]["messageType"]]["caption"])) { 1001 | $this->from->caption = $data["data"]["msgContent"][$data["data"]["messageType"]]["caption"]; 1002 | } 1003 | } 1004 | } 1005 | } 1006 | } 1007 | --------------------------------------------------------------------------------