sid, $this->token); $message = $twilio->messages->create( "whatsapp:+$whatsapp", // to [ "from" => "whatsapp:+{$this->numeroTwilio}", "mediaUrl" => [$link] ] ); logger('twilio')->info(var_export($message->body, true)); return $message->body; } function enviarMsg($whatsapp, $mensagem, $encode = true) { if ($encode) { $mensagem = utf8_encode($mensagem); } $twilio = new Client($this->sid, $this->token); $message = $twilio->messages->create( "whatsapp:+$whatsapp", // to [ "from" => "whatsapp:+{$this->numeroTwilio}", "body" => $mensagem, ] ); logger('twilio')->info(var_export($message->body, true)); return $message->body; } function enviarMsgIterativaLista($whatsapp, $mensagem, $nomeButton, $sections) { } function enviarMsgIterativaBotao($whatsapp, $mensagem, $buttons) { } function enviarContato($whatsapp, $nome, $contato) { } function enviarLocalizacao($whatsapp, $longitude, $latitude, $nome = null, $endereco = null) { } function baixarMidia() { $request = new Requests(); if (in_array($this->getType(), ['location', 'contacts', 'text'])) { return true; } logger('baixarMidia')->info('url: ' . $this->hook['MediaUrl0']); $request->setToken(base64_encode("ACab626d6f133aa20b21879d37cd21b139:131e5ed83468349ff93250ca72417d70")); $request->setUrl($this->hook['MediaUrl0']); $name = $this->getId(); $request->requestType("GET"); $request->setMetodo(''); $pathfile = $request->storage . $name; $retorno = $request->exec('Basic'); logger('baixarMidia')->info(var_export($retorno, true)); file_put_contents($pathfile, $retorno); if (file_exists($pathfile)) { return true; } return false; } function getProfile() { return $this->hook['ProfileName']; } function getPhone() { return $this->hook['WaId']; } function getType() { $type = $this->hook['MediaContentType0']; if ($type) { $type = explode('/', $type); if ($type[0] == 'application') { return 'document'; } return $type[0]; } return 'text'; } function getMimetype() { return $this->hook['MediaContentType0']; } function getId() { return $this->hook['MessageSid']; } function getIsValidMessage() { return is_array($this->hook); } function getMessage() { return $this->hook['Body']; } function setMessage($msg) { $this->hook['Body'] = $msg; } function getContactFormatted() { return false; } function getContactPhone() { return false; } function getGeolocation($type) { return false; } function setHook($hook) { //$array = "SmsMessageSid=SM3f3e0cac9d0da519ec0ffa7f15eaa15b&NumMedia=0&ProfileName=Lucas&SmsSid=SM3f3e0cac9d0da519ec0ffa7f15eaa15b&WaId=556596107663&SmsStatus=received&Body=sdsdfads&To=whatsapp%3A%2B14155238886&NumSegments=1&MessageSid=SM3f3e0cac9d0da519ec0ffa7f15eaa15b&AccountSid=ACab626d6f133aa20b21879d37cd21b139&From=whatsapp%3A%2B556596107663&ApiVersion=2010-04-01"; $array = explode("&", urldecode($hook)); $map = []; foreach ($array as $key => $value) { $auxi = $array = explode("=", $value); $map[$auxi[0]] = $auxi[1]; } // mensagem normal // [SmsMessageSid] => SM3f3e0cac9d0da519ec0ffa7f15eaa15b // [NumMedia] => 0 // [ProfileName] => Lucas // [SmsSid] => SM3f3e0cac9d0da519ec0ffa7f15eaa15b // [WaId] => 556596107663 // [SmsStatus] => received // [Body] => sdsdfads // [To] => whatsapp%3A%2B14155238886 // [NumSegments] => 1 // [MessageSid] => SM3f3e0cac9d0da519ec0ffa7f15eaa15b // [AccountSid] => ACab626d6f133aa20b21879d37cd21b139 // [From] => whatsapp%3A%2B556596107663 // [ApiVersion] => 2010-04-01 // imagem // [MediaContentType0] => image/jpeg // [SmsMessageSid] => MM0e531d626f74ec950e637d7491b0080c // [NumMedia] => 1 // [ProfileName] => Lucas // [SmsSid] => MM0e531d626f74ec950e637d7491b0080c // [WaId] => 556596107663 // [SmsStatus] => received // [Body] => // [To] => whatsapp:+14155238886 // [NumSegments] => 1 // [MessageSid] => MM0e531d626f74ec950e637d7491b0080c // [AccountSid] => ACab626d6f133aa20b21879d37cd21b139 // [From] => whatsapp:+556596107663 // [MediaUrl0] => https://api.twilio.com/2010-04-01/Accounts/ACab626d6f133aa20b21879d37cd21b139/Messages/MM0e531d626f74ec950e637d7491b0080c/Media/ME4ff81dee03f2cd1b7875d87954e8abd7 // [ApiVersion] => 2010-04-01 // documento n�o valido // [SmsMessageSid] => MM2f04ee178bf6843dd26ac19e6e193c19 // [NumMedia] => 0 // [ProfileName] => Lucas // [SmsSid] => MM2f04ee178bf6843dd26ac19e6e193c19 // [WaId] => 556596107663 // [SmsStatus] => received // [Body] => INSTALA��O WHATSAPP.docx // [To] => whatsapp:+553140428280 // [NumSegments] => 1 // [MessageSid] => MM2f04ee178bf6843dd26ac19e6e193c19 // [AccountSid] => ACab626d6f133aa20b21879d37cd21b139 // [From] => whatsapp:+556596107663 // [ApiVersion] => 2010-04-01 // documento pdf // [MediaContentType0] => application/pdf // [SmsMessageSid] => MM1042d93ac503a7468b7d3fb3a0ca77d5 // [NumMedia] => 1 // [ProfileName] => Lucas // [SmsSid] => MM1042d93ac503a7468b7d3fb3a0ca77d5 // [WaId] => 556596107663 // [SmsStatus] => received // [Body] => Cap1-_atlas_.pdf // [To] => whatsapp:+553140428280 // [NumSegments] => 1 // [MessageSid] => MM1042d93ac503a7468b7d3fb3a0ca77d5 // [AccountSid] => ACab626d6f133aa20b21879d37cd21b139 // [From] => whatsapp:+556596107663 // [MediaUrl0] => https://api.twilio.com/2010-04-01/Accounts/ACab626d6f133aa20b21879d37cd21b139/Messages/MM1042d93ac503a7468b7d3fb3a0ca77d5/Media/ME8fead4a393c68d2fcd14bdff03cc8e74 // [ApiVersion] => 2010-04-01 $this->hook = $map; } function retornaTituloDocument() { if ($this->getType() == 'text') { return null; } return $this->hook['Body']; } }