PHP code example of amo-tm / amosdk-php

1. Go to this page and download the library: Download amo-tm/amosdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

amo-tm / amosdk-php example snippets




use \Amo\Sdk\AmoClient;

$sdk = new AmoClient([
    'clientID' => 'your_client_id',
    'clientSecret' => 'your_client_secret',
]);

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,
]);

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

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();

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' => '[email protected]',
    'external_id' => '7688d6ac-57a1-421e-ac41-a68205d96d4e'
]));

print "profile created with id " . $createdTeam->getId();

/** @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'
]));

/** @var \Amo\Sdk\Service\TeamService $teamService */
$teamService->kick($invitedUser->getId());

/** @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();

@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();

@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();

@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();

@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();
bash
composer