Creación de documentos en Google drive basados ​​en eventos en sistemas CRM: amoCRM y Bitrix24

Caso práctico sobre cómo desarrollar su propio escenario de integración

Los servicios de Google para trabajar con documentos de texto (Google Docs) y hojas de cálculo (Google Sheets), que aparecieron en 2006, se complementaron 6 años después con la capacidad de trabajar con un disco virtual (Google Drive) y se ganaron el amor generalizado entre los usuarios, privando Microsoft de su monopolio de décadas de trabajo con software de oficina.





, , , Google-, , . Google-.





Google- CRM-. , « » , CRM- , Google Drive , , . , Google- .





CRM- Google 24 .





, 24 amoCRM . , ?





, - Google – : REST API Google Script. , REST API Google , , create . , , , API .





, , . - , , , CRM-.





1.

, , ID .





script .





, , Javascript, Google.





2. Google Cloud Platform

, «» . Google Cloud Platform. Enable Google Script API : https://developers.google.com/apps-script/api/quickstart/php.





API, credentials.json, . .





3.

, .





, PHP-.





4. PHP-

API Google , : composer require google/apiclient:^2.0  





:





function getClient()
{
    $client = new Google_Client();
    $client->setApplicationName('Google Apps Script API PHP Quickstart');
    //      
    $client->setScopes("https://www.googleapis.com/auth/documents https://www.googleapis.com/auth/drive");
    //  credential.json,   Google
$client->setAuthConfig('credentials.json');
    $client->setAccessType('offline');
    $client->setPrompt('select_account consent');

    //   token.json
    $tokenPath = 'token.json';
    if (file_exists($tokenPath)) {
        $accessToken = json_decode(file_get_contents($tokenPath), true);
        $client->setAccessToken($accessToken);
    }

    //    
    if ($client->isAccessTokenExpired()) {
        if ($client->getRefreshToken()) {
            $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
        } else {
            $authUrl = $client->createAuthUrl();
            printf("Open the following link in your browser:\n%s\n", $authUrl);
            print 'Enter verification code: ';
            $authCode = trim(fgets(STDIN));

            $accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
            print_r($accessToken);
            $client->setAccessToken($accessToken);
            
            if (array_key_exists('error', $accessToken)) {
                throw new Exception(join(', ', $accessToken));
            }
        }

        //    
        if (!file_exists(dirname($tokenPath))) {
            mkdir(dirname($tokenPath), 0700, true);
        }
        file_put_contents($tokenPath, json_encode($client->getAccessToken()));
    }
    return $client;
}
      
      



ssh – “php ( )”.





url, verification code url , 1, . (token.json), PHP-. ,  .





, , . 





//        
$client = getClient();
$service = new Google_Service_Script($client);

//   
$scriptId = '***********************wKhTTdKL7ChremS5AkvzwlPJARnxqisW7TzDB ';

$request = new Google_Service_Script_ExecutionRequest();
//       
$request->setFunction('FillTemplate');
$request->setParameters([$_REQUEST['customer'],$_REQUEST['link'],$_REQUEST['formsv'],$_REQUEST['socnet'],$_REQUEST['whatsi'],   $_REQUEST['ats'],$_REQUEST['pipeline'],$_REQUEST['outscope'],$_REQUEST['editor'],$_REQUEST['viewer']]);

try {
    // Make the API request.
    $response = $service->scripts->run($scriptId, $request);
    if ($response->getError()) {
        //  

        $error = $response->getError()['details'][0];
        printf("Script error message: %s\n", $error['errorMessage']);

        if (array_key_exists('scriptStackTraceElements', $error)) {
            print "Script error stacktrace:\n";
            foreach($error['scriptStackTraceElements'] as $trace) {
                printf("\t%s: %d\n", $trace['function'], $trace['lineNumber']);
            }
        }
    }     
} catch (Exception $e) {
    //  
    echo 'Caught exception: ', $e->getMessage(), "\n";
}
      
      



5. PHP- CRM

, CRM.





CRM , . c :





  • amoCRM;





  • 24.





, 24 -, Get- , -.





Google Drive:





URL, Get-. , 4 ( 2048 ).





Por lo tanto, si el texto transferido al documento es lo suficientemente largo, recomendamos que los usuarios de Bitrix24 escriban su propia activación de procesos comerciales. La información sobre los enfoques para su desarrollo se puede obtener de  este artículo








All Articles