Skip to content

Commit db898e5

Browse files
committed
Remove local application files and update examples
Deleted outdated local application files including .env, activity-handler.php, and robot-handler.php. Updated README with detailed instructions and examples on working with webhooks and local applications. Added a new composer.json for dependency management in the local-application directory. Signed-off-by: mesilov <[email protected]>
1 parent 2699496 commit db898e5

File tree

8 files changed

+173
-516
lines changed

8 files changed

+173
-516
lines changed

README.md

Lines changed: 116 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ API - level features
3535

3636
Performance improvements 🚀
3737

38-
- [x] Batch queries implemented with [PHP Generators](https://www.php.net/manual/en/language.generators.overview.php) – constant low memory and low CPI usage:
38+
- [x] Batch queries implemented with [PHP Generators](https://www.php.net/manual/en/language.generators.overview.php)
39+
constant low memory and low CPI usage:
3940
- [x] batch read data from bitrix24
4041
- [x] batch write data to bitrix24
4142
- [x] read without count flag
@@ -77,6 +78,7 @@ Performance improvements 🚀
7778
output: b24 response dto
7879
process: b24 entities, operate with immutable objects
7980
```
81+
8082
## Documentation
8183

8284
- [Bitrix24 API documentation - English](https://training.bitrix24.com/rest_help/)
@@ -99,12 +101,20 @@ Add `"mesilov/bitrix24-php-sdk": "2.x"` to `composer.json` of your application.
99101
## Examples
100102

101103
### Work with webhook
104+
102105
1. Go to `/examples/webhook` folder
103106
2. Open console and install dependencies
107+
104108
```shell
105109
composer install
106110
```
107-
3. Open example file and insert webhook url into `$webhookUrl`
111+
112+
3. Open Bitrix24 portal: Developer resources → Other → Inbound webhook
113+
4. Open example file and insert webhook url into `$webhookUrl`
114+
115+
<details>
116+
<summary>see example.php file</summary>
117+
108118
```php
109119
declare(strict_types=1);
110120

@@ -132,12 +142,103 @@ var_dump($b24Service->getMainScope()->main()->getCurrentUserProfile()->getUserPr
132142
// get deals list and address to first element
133143
var_dump($b24Service->getCRMScope()->lead()->list([], [], ['ID', 'TITLE'])->getLeads()[0]->TITLE);
134144
```
135-
4. call php file in cli
145+
146+
</details>
147+
148+
5. Call php file in shell
149+
136150
```shell
137151
php -f example.php
152+
```
153+
154+
### Work with local application
155+
156+
1. Go to `/examples/local-application` folder
157+
2. Open console and install dependencies
158+
159+
```shell
160+
composer install
161+
```
162+
163+
3. Start local development server
164+
165+
```shell
166+
sudo php -S 127.0.0.1:80
167+
```
168+
169+
4. Expose local server to public via [ngrok](https://ngrok.com/) and remember temporally public url –
170+
`https://****.ngrok-free.app`
171+
172+
```shell
173+
ngrok http 127.0.0.1
174+
```
175+
176+
5. Check public url from ngrok and see `x-powered-by` header with **200** status-code.
177+
178+
```shell
179+
curl https://****.ngrok-free.app -I
180+
HTTP/2 200
181+
content-type: text/html; charset=UTF-8
182+
date: Mon, 26 Aug 2024 19:09:24 GMT
183+
host: ****.ngrok-free.app
184+
x-powered-by: PHP/8.3.8
185+
```
186+
187+
6. Open Bitrix24 portal: Developer resources → Other → Local application and create new local application:
188+
- `type`: server
189+
- `handler path`: `https://****.ngrok-free.app/index.php`
190+
- `Initial installation path`: `https://****.ngrok-free.app/install.php`
191+
- `Menu item text`: `Test local app`
192+
- `scope`: `crm`
193+
7. Save application parameters in `index.php` file:
194+
- `Application ID (client_id)``BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID`
195+
- `Application key (client_secret)``BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET`
196+
- `Assing permitions (scope)``BITRIX24_PHP_SDK_APPLICATION_SCOPE`
197+
<details>
198+
<summary>see index.php file</summary>
199+
200+
```php
201+
declare(strict_types=1);
202+
203+
use Bitrix24\SDK\Core\Credentials\AuthToken;
204+
use Bitrix24\SDK\Core\Credentials\ApplicationProfile;
205+
use Bitrix24\SDK\Services\ServiceBuilderFactory;
206+
use Monolog\Handler\StreamHandler;
207+
use Monolog\Logger;
208+
use Monolog\Processor\MemoryUsageProcessor;
209+
use Symfony\Component\EventDispatcher\EventDispatcher;
210+
use Symfony\Component\HttpFoundation\Request;
211+
212+
require_once 'vendor/autoload.php';
213+
?>
214+
<pre>
215+
Application is worked, auth tokens from bitrix24:
216+
<?= print_r($_REQUEST, true) ?>
217+
</pre>
218+
<?php
219+
$request = Request::createFromGlobals();
138220

221+
$log = new Logger('bitrix24-php-sdk');
222+
$log->pushHandler(new StreamHandler('bitrix24-php-sdk.log'));
223+
$log->pushProcessor(new MemoryUsageProcessor(true, true));
224+
225+
$b24ServiceBuilderFactory = new ServiceBuilderFactory(new EventDispatcher(), $log);
226+
$appProfile = ApplicationProfile::initFromArray([
227+
'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => 'INSERT_HERE_YOUR_DATA',
228+
'BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET' => 'INSERT_HERE_YOUR_DATA',
229+
'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'INSERT_HERE_YOUR_DATA'
230+
]);
231+
$b24Service = $b24ServiceBuilderFactory->initFromRequest($appProfile, AuthToken::initFromPlacementRequest($request), $request->get('DOMAIN'));
232+
233+
var_dump($b24Service->getMainScope()->main()->getCurrentUserProfile()->getUserProfile());
234+
// get deals list and address to first element
235+
var_dump($b24Service->getCRMScope()->lead()->list([], [], ['ID', 'TITLE'])->getLeads()[0]->TITLE);
139236
```
140237

238+
</details>
239+
8. Save local application in Bitrix24 tab and press «OPEN APPLICATION» button.
240+
241+
141242
### Create application for Bitrix24 marketplace
142243

143244
if you want to create application you can use production-ready contracts in namespace
@@ -146,16 +247,22 @@ if you want to create application you can use production-ready contracts in name
146247
- `Bitrix24Accounts` — Store auth tokens and
147248
provides [methods](src/Application/Contracts/Bitrix24Accounts/Docs/Bitrix24Accounts.md) for work with Bitrix24
148249
account.
149-
- `ApplicationInstallations` — Store information about [application installation](src/Application/Contracts/ApplicationInstallations/Docs/ApplicationInstallations.md), linked with Bitrix24 Account with auth
250+
- `ApplicationInstallations` — Store information
251+
about [application installation](src/Application/Contracts/ApplicationInstallations/Docs/ApplicationInstallations.md),
252+
linked with Bitrix24 Account with auth
150253
tokens. Optional can store links to:
151254
- Client contact person: client person who responsible for application usage
152255
- Bitrix24 Partner contact person: partner contact person who supports client and configure application
153256
- Bitrix24 Partner: partner who supports client portal
154-
- `ContactPersons` – Store information [about person](src/Application/Contracts/ContactPersons/Docs/ContactPersons.md) who installed application.
155-
- `Bitrix24Partners` – Store information about [Bitrix24 Partner](src/Application/Contracts/Bitrix24Partners/Docs/Bitrix24Partners.md) who supports client portal and install or configure application.
257+
- `ContactPersons` – Store information [about person](src/Application/Contracts/ContactPersons/Docs/ContactPersons.md)
258+
who installed application.
259+
- `Bitrix24Partners` – Store information
260+
about [Bitrix24 Partner](src/Application/Contracts/Bitrix24Partners/Docs/Bitrix24Partners.md) who supports client
261+
portal and install or configure application.
156262

157263
Steps:
158-
1. Create own entity of this bounded contexts.
264+
265+
1. Create own entity of this bounded contexts.
159266
2. Implement all methods in contract interfaces.
160267
3. Test own implementation behavior with contract-tests `tests/Unit/Application/Contracts/*` – examples.
161268

@@ -171,13 +278,15 @@ Call in command line
171278
```shell
172279
make lint-phpstan
173280
```
281+
174282
### PHP Static Analysis Tool – rector
175283

176284
Call in command line for validate
177285

178286
```shell
179287
make lint-rector
180288
```
289+
181290
Call in command line for fix codebase
182291

183292
```shell

examples/application/local/.env

Lines changed: 0 additions & 8 deletions
This file was deleted.

examples/application/local/activity-handler.php

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)