|
|
|
@ -3,41 +3,45 @@
|
|
|
|
|
namespace app\Providers; |
|
|
|
|
|
|
|
|
|
use app\Interfaces\IApiMedia; |
|
|
|
|
use app\Models\NumberChannelModel; |
|
|
|
|
use Twilio\Rest\Client; |
|
|
|
|
|
|
|
|
|
class ApiTwilio implements IApiMedia |
|
|
|
|
{ |
|
|
|
|
private $sid = 'ACab626d6f133aa20b21879d37cd21b139'; |
|
|
|
|
private $token = CONF_WHATSAPP_AUTH_TOKEN; //'131e5ed83468349ff93250ca72417d70'; |
|
|
|
|
private $numeroTwilio = CONF_WHATSAPP_NUMBER; //'553140428280'; |
|
|
|
|
|
|
|
|
|
/** @var string $hook resposta do webhook */ |
|
|
|
|
// private $sid = 'ACab626d6f133aa20b21879d37cd21b139'; |
|
|
|
|
// private $token = CONF_WHATSAPP_AUTH_TOKEN; //'131e5ed83468349ff93250ca72417d70'; |
|
|
|
|
// private $numeroTwilio = CONF_WHATSAPP_NUMBER; //'553140428280'; |
|
|
|
|
private $hook; |
|
|
|
|
protected NumberChannelModel $number; |
|
|
|
|
|
|
|
|
|
function __construct(NumberChannelModel $number) |
|
|
|
|
{ |
|
|
|
|
$this->number = $number; |
|
|
|
|
} |
|
|
|
|
function getContentType() |
|
|
|
|
{ |
|
|
|
|
return 'text/xml'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getchannel() |
|
|
|
|
function getchannel(): string |
|
|
|
|
{ |
|
|
|
|
return CONF_WHATSAPP_CHANNEL; |
|
|
|
|
} |
|
|
|
|
function enviarMedia($whatsapp, $link, $type, $titulo = null) |
|
|
|
|
{ |
|
|
|
|
/* |
|
|
|
|
twilio só suporta esses formatos. |
|
|
|
|
twilio s<EFBFBD> suporta esses formatos. |
|
|
|
|
Images JPG, JPEG, PNG |
|
|
|
|
Audio MP3, OGG, AMR |
|
|
|
|
Documents PDF |
|
|
|
|
Video MP4 (with H.264 video codec and AAC audio) |
|
|
|
|
Contacts vCard (.vcf)*/ |
|
|
|
|
|
|
|
|
|
$twilio = new Client($this->sid, $this->token); |
|
|
|
|
$twilio = new Client($this->number->work_space, $this->number->token); |
|
|
|
|
$message = $twilio->messages->create( |
|
|
|
|
"whatsapp:+$whatsapp", // to |
|
|
|
|
[ |
|
|
|
|
"from" => "whatsapp:+{$this->numeroTwilio}", |
|
|
|
|
"from" => "whatsapp:+{$this->number->number}", |
|
|
|
|
"mediaUrl" => [$link] |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
@ -49,29 +53,17 @@ class ApiTwilio implements IApiMedia
|
|
|
|
|
if ($encode) { |
|
|
|
|
$mensagem = utf8_encode($mensagem); |
|
|
|
|
} |
|
|
|
|
$twilio = new Client($this->sid, $this->token); |
|
|
|
|
$twilio = new Client($this->number->work_space, $this->number->token); |
|
|
|
|
$message = $twilio->messages->create( |
|
|
|
|
"whatsapp:+$whatsapp", // to |
|
|
|
|
[ |
|
|
|
|
"from" => "whatsapp:+{$this->numeroTwilio}", |
|
|
|
|
"from" => "whatsapp:+{$this->number->number}", |
|
|
|
|
"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(); |
|
|
|
@ -79,7 +71,7 @@ class ApiTwilio implements IApiMedia
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
logger('baixarMidia')->info('url: ' . $this->hook['MediaUrl0']); |
|
|
|
|
$request->setToken(base64_encode("{$this->sid}:{$this->token}")); |
|
|
|
|
$request->setToken(base64_encode("{$this->number->work_space}:{$this->number->token}")); |
|
|
|
|
$request->setUrl($this->hook['MediaUrl0']); |
|
|
|
|
$name = $this->getId(); |
|
|
|
|
$request->requestType("GET"); |
|
|
|
@ -134,92 +126,12 @@ class ApiTwilio implements IApiMedia
|
|
|
|
|
{ |
|
|
|
|
$this->hook['Body'] = $msg; |
|
|
|
|
} |
|
|
|
|
function getContactFormatted() |
|
|
|
|
{ |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
function getContactPhone() |
|
|
|
|
{ |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
function getGeolocation($type) |
|
|
|
|
{ |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
function setHook($hook) |
|
|
|
|
|
|
|
|
|
function setHook(array $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; |
|
|
|
|
$this->hook = $hook; |
|
|
|
|
} |
|
|
|
|
function retornaTituloDocument() |
|
|
|
|
{ |
|
|
|
@ -228,4 +140,8 @@ class ApiTwilio implements IApiMedia
|
|
|
|
|
} |
|
|
|
|
return $this->hook['Body']; |
|
|
|
|
} |
|
|
|
|
function getNumberChannel(): NumberChannelModel |
|
|
|
|
{ |
|
|
|
|
return $this->number; |
|
|
|
|
} |
|
|
|
|
} |