-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5f8454
commit 221e138
Showing
7 changed files
with
886 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# These are some examples of commonly ignored file patterns. | ||
# You should customize this list as applicable to your project. | ||
# Learn more about .gitignore: | ||
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore | ||
|
||
# Node artifact files | ||
node_modules/ | ||
dist/ | ||
vendor/ | ||
|
||
# Compiled Java class files | ||
*.class | ||
|
||
# Compiled Python bytecode | ||
*.py[cod] | ||
|
||
# Log files | ||
*.log | ||
|
||
# Package files | ||
*.jar | ||
|
||
# Maven | ||
target/ | ||
dist/ | ||
|
||
# JetBrains IDE | ||
.idea/ | ||
|
||
# Unit test reports | ||
TEST*.xml | ||
|
||
# Generated by MacOS | ||
.DS_Store | ||
|
||
# Generated by Windows | ||
Thumbs.db | ||
|
||
# Applications | ||
*.app | ||
*.exe | ||
*.war | ||
|
||
# Large media files | ||
*.mp4 | ||
*.tiff | ||
*.avi | ||
*.flv | ||
*.mov | ||
*.wmv | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
namespace EvolutionSDK; | ||
|
||
use EvolutionSDK\util\Config; | ||
use EvolutionSDK\util\EndPoints; | ||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Exception\ClientException; | ||
class SDK | ||
{ | ||
protected Client $httpclient; | ||
protected Config $config; | ||
/** | ||
* receive Config instance | ||
* | ||
* @param Config $config | ||
* @return void | ||
*/ | ||
public function __construct(Config $config) | ||
{ | ||
$this->config = $config; | ||
$this->httpclient = new Client( | ||
[ | ||
'base_uri' => $config->getUrl(), | ||
'timeout' => 10 | ||
] | ||
); | ||
} | ||
/** | ||
* create instance | ||
* | ||
* @param string $instance | ||
* @param bool $qrcode | ||
* @return \StdClass | ||
*/ | ||
public function create(string $instance, $qrcode = false) | ||
{ | ||
try { | ||
|
||
$output = $this->httpclient->request( | ||
'POST', | ||
EndPoints::CREATE, | ||
[ | ||
'headers' => $this->setConfigHeader(), | ||
'json' => [ | ||
'instanceName' => $instance, | ||
'qrcode' => $qrcode | ||
] | ||
] | ||
); | ||
return json_decode($output->getBody()->getContents()); | ||
} catch (ClientException $e) { | ||
var_dump($e->getMessage()); | ||
} | ||
|
||
} | ||
/** | ||
* sendMessage | ||
* | ||
* @param string $instance | ||
* @param string $number | ||
* @param string $message | ||
* @param array $options | ||
* @return \stdClass | ||
*/ | ||
public function sendMessage(string $instance, string $number, string $message, array $options = []) | ||
{ | ||
$number = $number . '@s.whatsapp.net'; | ||
try { | ||
$output = $this->httpclient->request( | ||
'POST', | ||
EndPoints::SEND . $instance, | ||
[ | ||
'headers' => $this->setConfigHeader(), | ||
'json' => [ | ||
'number' => $number, | ||
'textMessage' => [ | ||
'text' => $message | ||
], | ||
'options' => $options | ||
] | ||
] | ||
); | ||
return json_decode($output->getBody()->getContents()); | ||
} catch (ClientException $e) { | ||
var_dump($e->getMessage()); | ||
} | ||
} | ||
/** | ||
* connect qrcode from specif instance | ||
* | ||
* @param string $instance | ||
* @return void | ||
*/ | ||
public function connect(string $instance) | ||
{ | ||
try { | ||
$output = $this->httpclient->request( | ||
'GET', | ||
EndPoints::CONNECT . $instance, | ||
[ | ||
'headers' => $this->setConfigHeader() | ||
] | ||
); | ||
return json_decode($output->getBody()->getContents()); | ||
} catch (ClientException $e) { | ||
var_dump($e->getMessage()); | ||
} | ||
} | ||
public function instanceStatus(string $instance) | ||
{ | ||
try { | ||
$output = $this->httpclient->request( | ||
'GET', | ||
EndPoints::STATUS . $instance, | ||
[ | ||
'headers' => $this->setConfigHeader() | ||
] | ||
); | ||
return json_decode($output->getBody()->getContents()); | ||
} catch (ClientException $e) { | ||
var_dump($e->getMessage()); | ||
} | ||
} | ||
/* private methods */ | ||
/** | ||
* get header with apikey | ||
* | ||
* @return array | ||
*/ | ||
private function setConfigHeader(): array | ||
{ | ||
return [ | ||
'apiKey' => $this->config->getApikey() | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
namespace EvolutionSDK\util; | ||
class Config{ | ||
|
||
private string $url = ''; | ||
private string $apikey = ''; | ||
/** | ||
* get url param | ||
* | ||
* @return string | ||
*/ | ||
public function getUrl(){ | ||
return $this->url; | ||
} | ||
/** | ||
* get apikey param | ||
* | ||
* @return string | ||
*/ | ||
public function getApikey(){ | ||
return $this->apikey; | ||
} | ||
/** | ||
* setUrl | ||
* | ||
* @param string $url | ||
* @return void | ||
*/ | ||
public function setUrl(string $url){ | ||
$this->url = $url; | ||
} | ||
/** | ||
* set apikey param | ||
* | ||
* @param string $apikey | ||
* @return void | ||
*/ | ||
public function setApikey(string $apikey){ | ||
$this->apikey = $apikey; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
namespace EvolutionSDK\util; | ||
class EndPoints{ | ||
public const CREATE = '/instance/create/'; | ||
public const CONNECT = '/instance/connect/'; | ||
public const SEND = '/message/sendText/'; | ||
public const STATUS = '/instance/connectionState/'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "cyber-root0/evolution-sdk", | ||
"type": "library", | ||
"authors": [ | ||
{ | ||
"email": "[email protected]", | ||
"name": "Bruno Alves", | ||
"role": "Web Developer" | ||
} | ||
], | ||
"version": "1.1.0", | ||
"description": "SDK Para consumir API evolution do WhatsApp", | ||
"autoload": { | ||
"psr-4": { | ||
"EvolutionSDK\\": "SDK/" | ||
} | ||
}, | ||
"require": { | ||
"guzzlehttp/guzzle": "*" | ||
} | ||
} |
Oops, something went wrong.