Skip to content

Commit e6ff656

Browse files
committed
Add application installation interface and Bitrix24 ID to contact person
This update adds an application installation interface for setting up interactions between the application and the Bitrix24 API. A Bitrix24 user ID field is also added to the contact person interface. This modification extends the functionality of the contact person, enabling more advanced data tracking. The new ID field maps a Bitrix24 user with a contact person, if there is any association. Signed-off-by: mesilov <[email protected]>
1 parent 00a3f89 commit e6ff656

File tree

26 files changed

+1331
-66
lines changed

26 files changed

+1331
-66
lines changed

examples/LoggerFactory.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Monolog\Handler\StreamHandler;
6+
use Monolog\Logger;
7+
use Monolog\Processor\IntrospectionProcessor;
8+
use Monolog\Processor\MemoryUsageProcessor;
9+
use Psr\Log\LoggerInterface;
10+
11+
class LoggerFactory
12+
{
13+
public static function get(): LoggerInterface
14+
{
15+
$log = new Logger('bitrix24-php-sdk');
16+
$log->pushHandler(new StreamHandler($_ENV['LOGS_FILE_NAME'], (int)$_ENV['LOGS_LEVEL']));
17+
$log->pushProcessor(new MemoryUsageProcessor(true, true));
18+
$log->pushProcessor(new IntrospectionProcessor((int)$_ENV['LOGS_LEVEL']));
19+
20+
return $log;
21+
}
22+
}

examples/application/local/.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# monolog
2+
LOGS_LEVEL=100
3+
LOGS_FILE_NAME=bitrix24-php-sdk.log
4+
5+
# local application secret parameters
6+
BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID=
7+
BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET=
8+
BITRIX24_PHP_SDK_APPLICATION_SCOPE=
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use Bitrix24\SDK\Core\Credentials\AuthToken;
5+
use Bitrix24\SDK\Core\Credentials\ApplicationProfile;
6+
use Bitrix24\SDK\Services\ServiceBuilderFactory;
7+
use Bitrix24\SDK\Services\Workflows\Common\WorkflowPropertyType;
8+
use Bitrix24\SDK\Services\Workflows\Workflow\Request\IncomingRobotRequest;
9+
use Monolog\Handler\StreamHandler;
10+
use Monolog\Logger;
11+
use Monolog\Processor\MemoryUsageProcessor;
12+
use Symfony\Component\Console\Input\ArgvInput;
13+
use Symfony\Component\Dotenv\Dotenv;
14+
use Symfony\Component\ErrorHandler\Debug;
15+
use Symfony\Component\EventDispatcher\EventDispatcher;
16+
use Symfony\Component\HttpFoundation\Request;
17+
18+
require dirname(__DIR__, 3) . '/vendor/autoload.php';
19+
20+
?>
21+
<pre>
22+
Приложение работает, получили токены от Битрикс24:
23+
<?= print_r($_REQUEST, true) ?>
24+
</pre>
25+
<?php
26+
if (!class_exists(Dotenv::class)) {
27+
throw new LogicException('You need to add "symfony/dotenv" as Composer dependencies.');
28+
}
29+
30+
(new Dotenv())->bootEnv('.env');
31+
32+
if ($_SERVER['APP_DEBUG']) {
33+
umask(0000);
34+
35+
if (class_exists(
36+
Debug::class
37+
)) {
38+
Debug::enable();
39+
}
40+
}
41+
42+
43+
try {
44+
$log = new Logger('bitrix24-php-sdk-cli');
45+
$log->pushHandler(new StreamHandler($_ENV['LOGS_FILE_NAME'], (int)$_ENV['LOGS_LEVEL']));
46+
$log->pushProcessor(new MemoryUsageProcessor(true, true));
47+
48+
$req = Request::createFromGlobals();
49+
$log->debug('incoming request', [
50+
'payload' => $req->request->all()
51+
]);
52+
53+
$workflowReq = IncomingRobotRequest::initFromRequest($req);
54+
55+
print_r($workflowReq);
56+
57+
$b24ServiceFactory = new ServiceBuilderFactory(new EventDispatcher(), $log);
58+
$appProfile = ApplicationProfile::initFromArray($_ENV);
59+
60+
//AccessToken::initFromWorkflowRequest($req),
61+
$b24Service = $b24ServiceFactory->initFromRequest(
62+
$appProfile,
63+
$workflowReq->auth->accessToken,
64+
$workflowReq->auth->domain
65+
);
66+
67+
$returnProp = [
68+
'result_sum' => 5555
69+
];
70+
71+
print('PROP' . PHP_EOL);
72+
print_r($workflowReq->properties);
73+
print_r($b24Service->getMainScope()->main()->getCurrentUserProfile()->getUserProfile());
74+
75+
$b24Service->getBizProcScope()->activity()->log(
76+
$workflowReq->eventToken,
77+
'hello from activity handler'
78+
);
79+
80+
$res = $b24Service->getBizProcScope()->event()->send(
81+
$workflowReq->eventToken,
82+
$returnProp,
83+
sprintf('debug result %s', print_r($returnProp, true))
84+
);
85+
$log->debug('ffffffff', [
86+
'res' => $res->isSuccess()
87+
]);
88+
89+
} catch (Throwable $exception) {
90+
91+
$log->error(sprintf('error: %s', $exception->getMessage()), [
92+
'trace' => $exception->getTraceAsString()
93+
]);
94+
95+
print('ERRRRRRRRRORRRR!!!!');
96+
print($exception->getMessage() . PHP_EOL);
97+
print_r($exception->getTraceAsString());
98+
99+
}
100+
101+
102+
// Array
103+
// (
104+
// [workflow_id] => 664fa13bbbb410.99176768
105+
// [code] => test_activity
106+
// [document_id] => Array
107+
// (
108+
// [0] => crm
109+
// [1] => CCrmDocumentContact
110+
// [2] => CONTACT_109286
111+
// )
112+
//
113+
// [document_type] => Array
114+
// (
115+
// [0] => crm
116+
// [1] => CCrmDocumentContact
117+
// [2] => CONTACT
118+
// )
119+
//
120+
// [event_token] => 664fa13bbbb410.99176768|A40364_79843_85254_57332|MS1ekdI0CvXi8ycL8qNIn96hak8JEndG.54020ce210345fb6eb12a79d75316d9430b42ccd9c1d82ab1a3bf8b064ec50e9
121+
// [properties] => Array
122+
// (
123+
// [comment] => дефолтная строка - значение
124+
// [amount] => 333
125+
// )
126+
//
127+
// [use_subscription] => Y
128+
// [timeout_duration] => 660
129+
// [ts] => 1716494651
130+
131+
// [auth] => Array
132+
// (
133+
134+
// access token
135+
// [access_token] => 4baf4f66006e13540058f18a000000100000009b41bce7ec85f07c3646c07e6d629e7c
136+
// [refresh_token] => 3b2e7766006e13540058f18a000000100000003b31a96730e79dc7561c1d7d0b33933f
137+
// [expires] => 1716498251
138+
139+
// endpoints
140+
// [server_endpoint] => https://oauth.bitrix.info/rest/
141+
// [client_endpoint] => https://bitrix24-php-sdk-playground.bitrix24.ru/rest/
142+
143+
// scope
144+
// [scope] => crm,bizproc,appform,baas,placement,user_brief,call,telephony
145+
146+
// application status
147+
// [status] => L
148+
149+
150+
// [application_token] => f9ac5db5ad4adbdee13eb034207d8fbd
151+
// [expires_in] => 3600
152+
// [domain] => bitrix24-php-sdk-playground.bitrix24.ru
153+
// [member_id] => 010b6886ebc205e43ae65000ee00addb
154+
// [user_id] => 16
155+
// )
156+
//)
5.68 KB
Binary file not shown.

0 commit comments

Comments
 (0)