amo-tm / amosdk-php
php sdk for amo | team messenger API
v1.3.23-beta
2023-03-09 18:17 UTC
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- guzzlehttp/guzzle: ^6.0 || ^7.0
- lcobucci/jwt: 4.1.5
- league/oauth2-client: 2.6.*
- nesbot/carbon: 2.*
- ramsey/uuid: ^4.2 || ^4.3
Requires (Dev)
- phpunit/phpunit: 7.* || 8.*
- squizlabs/php_codesniffer: 3.5.*
- dev-v1.3-dev
- dev-v1.0.0-BETA
- v1.3.x-dev
- v1.3.23-beta
- v1.3.22-beta
- v1.3.21-beta
- v1.3.20-beta
- v1.3.19-beta
- v1.3.18-beta
- v1.3.17-beta
- v1.3.16-beta
- v1.3.15-beta
- v1.3.14-beta
- v1.3.13-beta
- v1.3.12-beta
- v1.3.11-beta
- v1.3.10-beta
- v1.3.9-beta
- v1.3.8-beta
- v1.3.7-beta
- v1.3.6-beta
- v1.3.5-beta
- v1.3.4-beta
- v1.3.3-beta
- v1.3.2-beta
- v1.3.1-beta
- v1.3.0.x-dev
- v1.3.0-beta
- v1.0.2-BETA
- v1.0.1-BETA
- v1.0.0-BETA
- dev-feature/create_subject
- dev-v1.0.2-BETA
This package is auto-updated.
Last update: 2024-11-06 11:52:16 UTC
README
Requirements
PHP 7.4.0 and later.
Composer
You can install the sdk via Composer. Run the following command:
composer require amo-tm/amosdk-php:"^v1.3@beta
To use the sdk, use Composer's autoload:
require_once('vendor/autoload.php');
Getting Started
Simple usage:
use \Amo\Sdk\AmoClient; $sdk = new AmoClient([ 'clientID' => 'your_client_id', 'clientSecret' => 'your_client_secret', ]);
Initiate client with access token:
use \Amo\Sdk\AmoClient; use \League\OAuth2\Client\Token\AccessToken; // Token fetch from store /** @var AccessToken $accessToken */ $accessToken = null; $sdk = new AmoClient([ 'clientID' => 'your_client_id', 'clientSecret' => 'your_client_secret', 'accessToken' => $accessToken, ]);
Receive appToken
This type of tokens issued by client library. Your can issue token on every request or store them in your datastore.
use \Amo\Sdk\AmoClient; $sdk = new AmoClient([ 'clientID' => 'your_client_id', 'clientSecret' => 'your_client_secret', ]); $appScopedSdk = $sdk->withToken($sdk->getApplicationToken(['teams', 'profiles'])) // store token in database
Create team
REQUIRED: AppToken
SCOPE: teams
use \Amo\Sdk\AmoClient; use \Amo\Sdk\Models\Team; $sdk = new AmoClient([ 'clientID' => 'your_client_id', 'clientSecret' => 'your_client_secret', ]); $appScopedSdk = $sdk->withToken($sdk->getApplicationToken(['teams', 'profiles'])) $newTeam = $appScopedSdk->team()->create(new Team([ 'title' => 'testTeamName' ])) print "team created with id " . $newTeam->getId();
Create profile
REQUIRED: AppToken
SCOPE: profiles
use \Amo\Sdk\AmoClient; use \Amo\Sdk\Models\Team; $sdk = new AmoClient([ 'clientID' => 'your_client_id', 'clientSecret' => 'your_client_secret', ]); $appScopedSdk = $sdk->withToken($sdk->getApplicationToken(['teams', 'profiles'])) $createdProfile = $appScopedSdk->profile()->create(new Profile([ 'name' => 'Tim', 'email' => 'tim@domain.com', 'external_id' => '7688d6ac-57a1-421e-ac41-a68205d96d4e' ])); print "profile created with id " . $createdTeam->getId();
Invite profile to team
REQUIRED: TeamToken
SCOPE: profiles,teams
/** @var \Amo\Sdk\AmoClient $appScopedSdk */ $teamService = $appScopedSdk->team($newTeam->getId())->scope(); // save team token to datastore $teamToken = $teamService->getAccessToken(); $invitedUser = $teamService->invite($createdProfile->getId(), new TeamProps([ 'is_admin' => true, 'position' => 'CEO' ]));
Kick profile from team
REQUIRED: TeamToken
SCOPE: profiles,teams
/** @var \Amo\Sdk\Service\TeamService $teamService */ $teamService->kick($invitedUser->getId());
Subject create
REQUIRED: TeamToken
/** @var \Amo\Sdk\Service\TeamService $teamService */ $subjectService = $teamService->subject(); $newSubject = $subjectService->create(new Subject([ 'title' => 'Subject Title', 'external_link' => 'https://example.com/', 'author' => Participant::user($createdProfile), 'participants' => new ParticipantCollection([ Participant::user($createdProfile->getId()), Participant::department('04469c3e-5f2e-11ec-bf63-0242ac130002'), Participant::accessList('0eba2bd6-5f2e-11ec-bf63-0242ac130002'), Participant::bot('124479fa-5f2e-11ec-bf63-0242ac130002'), ), 'subscribers' => new ParticipantCollection([ Participant::user('ebfaf836-f07b-4df5-809c-2bedb4a2f924'), Participant::department('04469c3e-5f2e-11ec-bf63-0242ac130002'), Participant::accessList('0eba2bd6-5f2e-11ec-bf63-0242ac130002'), Participant::bot('124479fa-5f2e-11ec-bf63-0242ac130002'), ), 'threads' => new SubjectThreadCollection([ new SubjectThread([ 'title' => 'Subject Thread #1', 'avatar_url' => 'https://picsum.photos/600' ]), new SubjectThread([ 'title' => 'Subject Thread #2', 'avatar_url' => 'https://picsum.photos/600' ]), ]), 'status' => new SubjectStatusCollection([ SubjectStatus::status('Status', '#F9F6EE'), SubjectStatus::status('Title', '#CFE1A7'), ]) ])); print "subject created with id " . $newSubject->getId();
Subject participants add
REQUIRED: TeamToken
@var \Amo\Sdk\Service\TeamService $teamService */ $subjectService = $teamService->subject($createdSubject->getId()); $participantsAddResponse = $subjectServie->participantsAdd([ new ParticipantCollection( Participant::user('d31f3f74-6fc0-41ae-b2f9-42eccd4f80b8'), Participant::department('04469c3e-5f2e-11ec-bf63-0242ac130002'), Participant::accessList('0eba2bd6-5f2e-11ec-bf63-0242ac130002'), Participant::bot('124479fa-5f2e-11ec-bf63-0242ac130002'), ) ]); print 'count current participants: '. $participantsAddResponse->getCount();
Subject participants remove
REQUIRED: TeamToken
@var \Amo\Sdk\Service\SubjectService $subjectService */ $participantsRemoveResponse = $subjectService->participantsRemove([ new ParticipantCollection( Participant::user('d31f3f74-6fc0-41ae-b2f9-42eccd4f80b8'), Participant::department('04469c3e-5f2e-11ec-bf63-0242ac130002'), Participant::accessList('0eba2bd6-5f2e-11ec-bf63-0242ac130002'), Participant::bot('124479fa-5f2e-11ec-bf63-0242ac130002'), ) ]); print 'count current participants: '. $participantsRemoveResponse->getCount();
Subject subscribers add
REQUIRED: TeamToken
@var \Amo\Sdk\Service\SubjectService $subjectService */ $subscriberAddResponse = $subjectService->subscribersAdd([ new ParticipantCollection( Participant::user('d31f3f74-6fc0-41ae-b2f9-42eccd4f80b8'), Participant::department('04469c3e-5f2e-11ec-bf63-0242ac130002'), Participant::accessList('0eba2bd6-5f2e-11ec-bf63-0242ac130002'), Participant::bot('124479fa-5f2e-11ec-bf63-0242ac130002'), ) ]); print 'count current subscribers: '. $subscriberAddResponse->getCount();
Subject subscribers remove
REQUIRED: TeamToken
@var \Amo\Sdk\Service\SubjectService $subjectService */ $subscribersRemoveResponse = $subjectService->subscribersRemove([ new ParticipantCollection( Participant::user('d31f3f74-6fc0-41ae-b2f9-42eccd4f80b8'), Participant::department('04469c3e-5f2e-11ec-bf63-0242ac130002'), Participant::accessList('0eba2bd6-5f2e-11ec-bf63-0242ac130002'), Participant::bot('124479fa-5f2e-11ec-bf63-0242ac130002'), ) ]); print 'count current subscribers: '. $subscribersRemoveResponse->getCount();