-
Notifications
You must be signed in to change notification settings - Fork 7
Added support of partner API #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yuri-kovalev
wants to merge
3
commits into
green-api:master
Choose a base branch
from
yuri-kovalev:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -19,72 +19,85 @@ | |
| use GreenApi\RestApi\tools\ServiceMethods; | ||
| use GreenApi\RestApi\tools\Webhooks; | ||
| use GreenApi\RestApi\tools\Statuses; | ||
| use GreenApi\RestApi\tools\Partner; | ||
| use stdClass; | ||
|
|
||
| class GreenApiClient { | ||
| private $host; | ||
| private $media; | ||
| private $idInstance; | ||
| private $apiTokenInstance; | ||
| private $idInstance = null; | ||
| private $apiTokenInstance = null; | ||
| private $partnerToken = null; | ||
|
|
||
| /** | ||
| * @var Account | ||
| * @var Account|null | ||
| */ | ||
| public $account; | ||
| /** | ||
| * @var Sending | ||
| * @var Sending|null | ||
| */ | ||
| public $sending; | ||
| /** | ||
| * @var Groups | ||
| * @var Groups|null | ||
| */ | ||
| public $groups; | ||
| /** | ||
| * @var Journals | ||
| * @var Journals|null | ||
| */ | ||
| public $journals; | ||
| /** | ||
| * @var Marking | ||
| * @var Marking|null | ||
| */ | ||
| public $marking; | ||
| /** | ||
| * @var Queues | ||
| * @var Queues|null | ||
| */ | ||
| public $queues; | ||
| /** | ||
| * @var Receiving | ||
| * @var Receiving|null | ||
| */ | ||
| public $receiving; | ||
| /** | ||
| * @var ServiceMethods | ||
| * @var ServiceMethods|null | ||
| */ | ||
| public $serviceMethods; | ||
| /** | ||
| * @var Webhooks | ||
| * @var Webhooks|null | ||
| */ | ||
| public $webhooks; | ||
| /** | ||
| * @var Statuses | ||
| * @var Statuses|null | ||
| */ | ||
| public $statuses; | ||
| /** | ||
| * @var Partner|null | ||
| */ | ||
| public $partner; | ||
|
|
||
| public function __construct( $idInstance, $apiTokenInstance, $host = "https://api.green-api.com", $media = "https://media.green-api.com" ) { | ||
| public function __construct( $idInstance = null, $apiTokenInstance = null, $partnerToken = null, $host = "https://api.green-api.com", $media = "https://media.green-api.com" ) { | ||
|
|
||
| $this->idInstance = $idInstance; | ||
| $this->apiTokenInstance = $apiTokenInstance; | ||
| $this->host = $host; | ||
| $this->idInstance = $idInstance; | ||
| $this->apiTokenInstance = $apiTokenInstance; | ||
| $this->host = $host; | ||
| $this->media = $media; | ||
|
|
||
| $this->account = new Account( $this ); | ||
| $this->groups = new Groups( $this ); | ||
| $this->journals = new Journals( $this ); | ||
| $this->marking = new Marking( $this ); | ||
| $this->queues = new Queues( $this ); | ||
| $this->receiving = new Receiving( $this ); | ||
| $this->sending = new Sending( $this ); | ||
| $this->serviceMethods = new ServiceMethods( $this ); | ||
| $this->webhooks = new Webhooks( $this ); | ||
| $this->statuses = new Statuses( $this ); | ||
| $this->partnerToken = $partnerToken; | ||
|
|
||
| if ($this->idInstance && $this->apiTokenInstance) { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about this, but for partner API there is no need to use |
||
| $this->account = new Account( $this ); | ||
| $this->groups = new Groups( $this ); | ||
| $this->journals = new Journals( $this ); | ||
| $this->marking = new Marking( $this ); | ||
| $this->queues = new Queues( $this ); | ||
| $this->receiving = new Receiving( $this ); | ||
| $this->sending = new Sending( $this ); | ||
| $this->serviceMethods = new ServiceMethods( $this ); | ||
| $this->webhooks = new Webhooks( $this ); | ||
| $this->statuses = new Statuses( $this ); | ||
| } | ||
|
|
||
| if ($this->partnerToken) { | ||
| $this->partner = new Partner( $this ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -144,7 +157,7 @@ public function request( string $method, string $url, array $payload = null, boo | |
| break; | ||
| case 'POST_BINARY': | ||
| $mime_type = mime_content_type( $path ); | ||
| $headers = array( | ||
| $headers = array( | ||
| 'Content-Type: ' . $mime_type , | ||
| 'GA-Filename: ' . basename($path) | ||
| ); | ||
|
|
||
This file contains hidden or 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,79 @@ | ||
| <?php | ||
|
|
||
| namespace GreenApi\RestApi\tools; | ||
|
|
||
| use GreenApi\RestApi\GreenApiClient; | ||
| use stdClass; | ||
|
|
||
| class Partner { | ||
|
|
||
| /** | ||
| * @param GreenApiClient $greenApi | ||
| */ | ||
| private $greenApi; | ||
|
|
||
| /** | ||
| * @param GreenApiClient $greenApi | ||
| */ | ||
| public function __construct(GreenApiClient $greenApi) { | ||
| $this->greenApi = $greenApi; | ||
| } | ||
|
|
||
| /** | ||
| * The method is used to getting all the account instances created by the partner. | ||
| * | ||
| * @return stdClass | ||
| * @link https://green-api.com/en/docs/partners/getInstances/ | ||
| */ | ||
| public function getInstances(): stdClass { | ||
| return $this->greenApi->request('GET', | ||
| '{{host}}/partner/getInstances/{{partnerToken}}'); | ||
| } | ||
|
|
||
| /** | ||
| * The method is used to creating a messenger account instance on the partner's part | ||
| * | ||
| * @param $payload | ||
| * @return stdClass | ||
| * @link https://green-api.com/en/docs/partners/createInstance/ | ||
| */ | ||
| public function createInstance($payload): stdClass { | ||
| $defaultParameters = [ | ||
| 'name' => null, | ||
| 'webhookUrl' => null, | ||
| 'webhookUrlToken' => null, | ||
| 'delaySendMessagesMilliseconds' => null, | ||
| 'markIncomingMessagesReaded' => null, | ||
| 'markIncomingMessagesReadedOnReply' => null, | ||
| 'outgoingWebhook' => null, | ||
| 'outgoingMessageWebhook' => null, | ||
| 'outgoingAPIMessageWebhook' => null, | ||
| 'stateWebhook' => null, | ||
| 'incomingWebhook' => 'yes', | ||
| 'deviceWebhook' => null, | ||
| 'keepOnlineStatus' => null, | ||
| 'pollMessageWebhook' => null, | ||
| 'incomingBlockWebhook' => null, | ||
| 'incomingCallWebhook' => null, | ||
| 'editedMessageWebhook' => null, | ||
| 'deletedMessageWebhook' => null, | ||
| ]; | ||
|
|
||
| $requestParameters = array_filter(array_merge($defaultParameters, $payload)); | ||
|
|
||
| return $this->greenApi->request('GET', | ||
| '{{host}}/partner/createInstance/{{partnerToken}}', $requestParameters); | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * The method is used to deleting an instance of the partner's account. | ||
| * | ||
| * @return stdClass | ||
| * @link https://green-api.com/en/docs/partners/deleteInstanceAccount/ | ||
| */ | ||
| public function deleteInstanceAccount(): stdClass { | ||
| return $this->greenApi->request('GET', | ||
| '{{host}}/partner/deleteInstanceAccount/{{partnerToken}}'); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any way php support named arguments from 8 version
new GreenApiClient(idInstance: 'idInstance', apiTokenInstance: 'apiTokenInstance', partnerToken: 'partnerToken')