
Tarde o temprano, cualquier empresa de TI (outsourcing o supermercados) desea organizar su propio espacio donde puede almacenar información sobre proyectos, empleados y ventas. Mantener correspondencia de trabajo y discutir tareas / estrategias / documentos. Muy a menudo, tales compañías comienzan a codificar todo por sí mismas o vieron algo para Bitrix24, etc. En esta serie de artículos hablaré sobre nuestrouna bicicleta- Experiencia en automatización de procesos. Como era de esperar, casi todos son autohospedados, de código abierto e intentan hacerlo casi sin codificación.
Descargo de responsabilidad
Una serie de artículos describe un ejemplo de implementación de infraestructura: el autor no insta a repetir y no pretende ser "correcto" en tales enfoques. Algunas partes del sistema descrito se utilizan en realidad y con éxito en varias organizaciones durante 3 años. El autor acepta con gusto sugerencias para mejorar el sistema o sugerir soluciones alternativas. Por favor, no genere discusiones como "quién necesita esto" y "qué muletas", quién no necesita, no lea ni interfiera con los comentaristas
Entonces, ¿qué puede querer una empresa de outsourcing promedio de un sistema similar?
- Base de datos de empleados con distribución de derechos de acceso a la información.
- 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 .
- .
Preguntas frecuentes:
P: ¿Por qué es Node-RED en absoluto, si la solicitud se puede hacer directamente desde PHP a Yandex?
R: Al tener integración en el lado Node-RED, podemos cambiar la configuración, agregar nuevos servicios y enlaces, a los cambios del usuario, sin codificación adicional (sin contar las pequeñas funciones en Node-RED). El proceso de implementación de actualizaciones se reduce a un botón.