![](https://habrastorage.org/webt/j8/ml/pr/j8mlprykhqtqozupvqkxdxosez4.jpeg)
任何IT公司(外包或杂货店)迟早都希望组织自己的空间,您可以在其中存储有关项目,员工和销售的信息。保持工作往来并讨论任务/策略/文件。大多数情况下,此类公司开始自己编写所有代码,或者看到Bitrix24等产品。在本系列文章中,我将讨论我们的一辆自行车-流程自动化方面的经验。不出所料,几乎所有的自托管开放源代码都尝试几乎不用编码。
免责声明
一系列文章描述了基础结构实现的示例;作者并不敦促重复,也不假装在这种方法中是“正确的”。所描述系统的某些部分已在多个组织中实际成功地使用了3年。作者很乐意接受有关改进系统或提出替代解决方案的建议。请不要滋生那些不需要,不阅读且不干扰评论员的讨论,例如“谁需要这个”和“拐杖什么”
因此,一般的外包公司可以从类似的系统中获得什么:
- 分配了信息访问权的员工数据库
- GIT , , 1
- Chat-Server (Messenger ) 1
- , 1
- / HR
- -
- ( )
– . - , - .
![](https://habrastorage.org/webt/yl/5f/qy/yl5fqy_u63ucwcuv-0g81tmnmou.png)
, " GIT ?", " ?" . .
, . , , LDAP . LDAP , , . 3 LDAP OpenLDAP , , , .
, RESTapi. , LDAP .
, OpenSource ERP/CRM (Odoo, Axellor ), OpenProject . , . - PHP, .
, EspoCRM. , " " , . , , CMS, .
, Espo :
- HR
- -
- (CRM :))
PHP .
:
![](https://habrastorage.org/webt/xz/li/xe/xzlixei0uldejg7qnexbp7gtcmm.png)
CRM. .
( , ).
-> -> User ().
. ( ) :
![](https://habrastorage.org/webt/8h/xa/n4/8hxan49zron7it16falzbf9yjni.png)
, Skype, Telegram, VK, Facebook . (, ), , , , , ( ).
, .
/ .
-> -> -> .
- :
![](https://habrastorage.org/webt/9k/ei/5y/9kei5ycpejue5pz_fzi0ewwvnqc.png)
, , . , .
, - " " .
EspoCRM, . , - , - .
, . .
— . , . , — email.
— self-hosted . , , . .. 1000 , web- RESTapi. , — .
.
, , espo.
, , Node-RED.
Node-RED
, , .
Node-RED , : , - . , , , , .
Node-RED . , , API ..
API Token.
"-" - " URL ".
![](https://habrastorage.org/webt/lf/z8/bj/lfz8bjln_nzg5u5cx03wqoxieou.png)
, .
. Directory API, , , :
![](https://habrastorage.org/webt/ah/3w/qi/ah3wqil7oa6weq8zniwwg-djzei.png)
( )
- :
![](https://habrastorage.org/webt/c0/iw/cl/c0iwclk8yfgy5oxqqbw9muxaw2k.png)
, . , .
https://oauth.yandex.ru/authorize?response_type=token&client_id=<ID>
,
![](https://habrastorage.org/webt/_1/hh/lk/_1hhlkz1gx_ns8dllp-kuoltpfq.png)
.
, , Node-RED.
global.set('YaConnectToken', 'AgAAAA......');
return msg;
global.get() .
Inject , Flow 1. , . ,
![](https://habrastorage.org/webt/wx/-h/jg/wx-hjgxrlveknolkmmosz-g5ous.png)
Node-RED + .
- Flow : inject, function, http request
![](https://habrastorage.org/webt/r3/jo/c3/r3joc3phdkq4syialgwlog46opu.png)
- 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/
![](https://habrastorage.org/webt/_e/nj/41/_enj41flzzh_cange45c2zytdaq.png)
Deploy inject ( JSON inject function )
, http request , msg statusCode 200 201 payload:
![](https://habrastorage.org/webt/x0/fr/au/x0frau0ksvlpdpganr0vsw3vkcq.png)
! !
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 .
- .
常见问题解答:
问:如果可以直接从PHP向Yandex发出请求,为什么要使用Node-RED?
答:在Node-RED方面具有集成性,我们可以更改配置,添加新服务和挂钩,以适应用户更改,而无需进行其他编码(不计算Node-RED上的小功能)。部署更新的过程归结为一个按钮。