
Sooner or later, any IT company (outsourcing or grocery) has a desire to organize its own space where you can store information on projects, employees, and sales. Maintain working correspondence and discuss tasks / strategies / documents. Most often, such companies start to code everything themselves or saw something for Bitrix24, etc. In this series of articles I will talk about oura bike- experience in process automation. As expected, almost all self-hosted, opensource and try to do almost without coding.
Disclamer
A series of articles describes an example of the implementation of infrastructure; the author does not urge to repeat and does not pretend to be "correct" in such approaches. Some parts of the described system are actually and successfully used in several organizations for 3 years. The author gladly accepts suggestions for improving the system or suggesting alternative solutions. Please do not breed discussions like โwho needs thisโ and โwhat crutchesโ, who donโt need to, do not read and do not interfere with commentators
So, what can an average outsourcing company want from a similar system:
- Database of employees with distribution of access rights to information
- GIT , , 1
- Chat-Server (Messenger ) 1
- , 1
- / HR
- -
- ( )
โ . - , - .

, " GIT ?", " ?" . .
, . , , LDAP . LDAP , , . 3 LDAP OpenLDAP , , , .
, RESTapi. , LDAP .
, OpenSource ERP/CRM (Odoo, Axellor ), OpenProject . , . - PHP, .
, EspoCRM. , " " , . , , CMS, .
, Espo :
- HR
- -
- (CRM :))
PHP .
:

CRM. .
( , ).
-> -> User ().
. ( ) :

, Skype, Telegram, VK, Facebook . (, ), , , , , ( ).
, .
/ .
-> -> -> .
- :

, , . , .
, - " " .
EspoCRM, . , - , - .
, . .
โ . , . , โ email.
โ self-hosted . , , . .. 1000 , web- RESTapi. , โ .
.
, , espo.
, , Node-RED.
Node-RED
, , .
Node-RED , : , - . , , , , .
Node-RED . , , API ..
API Token.
"-" - " URL ".

, .
. Directory API, , , :

( )
- :

, . , .
https://oauth.yandex.ru/authorize?response_type=token&client_id=<ID>
,

.
, , Node-RED.
global.set('YaConnectToken', 'AgAAAA......');
return msg;
global.get() .
Inject , Flow 1. , . ,

Node-RED + .
- Flow : inject, function, http request

- inject, , , JSON
{
"userName":"testuser",
"firstName":"Test",
"lastName":"User",
"emailAddress":"testuser@mydomain.ru",
"dob":"1988-01-01",
"gender":"male",
"passwordConfirm":"12345678Eiru",
"isActive":true
}
.
- function :
const TOKEN = global.get('YaConnectToken');
const user = msg.payload;
const body = {
'department_id': 1,
'is_admin': false,
'nickname': user.userName,
'name': {
'first': user.firstName,
'last': user.lastName
},
'birthday': user.dob,
'gender': user.gender,
'password': user.passwordConfirm,
'is_dismissed': user.isActive,
'position': user.title
}
return {
headers: {
'Authorization': 'OAuth ' + TOKEN,
},
payload: body
}
.
http request, POST, url https://api.directory.yandex.net/v6/users/

Deploy inject ( JSON inject function )
, http request , msg statusCode 200 201 payload:

! !
EspoCRM Node-RED
( CRM) Node-RED .
PHP, .
UserSaved.php EspoCRM custom/Espo/Custom/Hooks/User
:
<?php
namespace Espo\Custom\Hooks\User;
use Espo\ORM\Entity;
class UserSaved extends \Espo\Core\Hooks\Base {
public function afterSave(Entity $entity, array $options = []) {
$entityValues = $entity->getValues();
unset($entityValues['password']);
$entityValues['isNew'] = $entity->isNew();
$data = array(
'event' => 'afterSave',
'entity' => $entityValues,
);
$this->_callRed($data);
}
public function afterRemove(Entity $entity, array $options = []) {
$entityValues = $entity->getValues();
unset($entityValues['password']);
$data = array(
'event' => 'afterRemove',
'entity' => $entityValues
);
$this->_callRed($data);
}
private function _callRed($data) {
$data_string = json_encode($data);
$ch = curl_init('__NODE_RED_ENDPOINT__');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}
Hook . ( ) , - // Espo, Node-RED. , Node-RED EspoCRM ( ) , localhost .
NODE_RED_ENDPOINT โ .
isNew ,
passwordConfirm , .
, .
:
Node-RED. , . Flow, . ( ).
EspoCRM , , , .
:
- self-hosted GIT ( GitLab :))
- self-hosted Slack
- HR .
- .
FAQ:
Q: Why is Node-RED at all, if the request can be made directly from PHP to Yandex?
A: Having integration on the Node-RED side, we can change the configuration, add new services and hooks, to user changes, without additional coding (not counting the small functions on Node-RED). The process of deploying updates comes down to one button.