-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
104 lines (95 loc) · 3.75 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const AmoCRM = require( 'amocrm-js' );
var AWS = require("aws-sdk");
AWS.config.update({region: 'eu-central-1'});
const crm = new AmoCRM({
domain: process.env.domain,
auth: {
login: process.env.auth_login,
hash: process.env.auth_hash
}
});
exports.handler = (event, context, callback) => {
event.Records.forEach((record) => {
if(record.dynamodb.NewImage == undefined){
console.log("Remove Lead");
}else{
console.log("Start Insert");
crm.Contact.insert([{
name: record.dynamodb.NewImage.customName.S,
responsible_user_id: "3316417",
tags: "купить майнер",
custom_fields: [
{
id: "543953",
name: 'Телефон',
code: 'PHONE',
values: [{
value: record.dynamodb.NewImage.phone.S,
enum: 907777
}],
is_system: true
},
{
id: "543955",
name: 'Email',
code: 'EMAIL',
values: [{
value: record.dynamodb.NewImage.email.S,
enum: 907789
}],
is_system: true
}
]
}])
.then(contact => {
console.log("Contanct ID", contact._response._embedded.items[0].id );
console.log(record.dynamodb.NewImage.TxAssetID.S, ": Add to Lead");
crm.Lead.insert([{
name: 'Покупка майнеров с client`а',
status_id: "29857402",
responsible_user_id: "55014691",
sale: 115,
tags: "buy_miner",
contacts_id: [
contact._response._embedded.items[0].id
],
custom_fields: [
{
id: 657873,
name: "Адрес доставки",
values: [{
value: record.dynamodb.NewImage.postCode.S + ', ' + record.dynamodb.NewImage.country.S + ', ' + record.dynamodb.NewImage.countryState.S + ', ' + record.dynamodb.NewImage.city.S + ', ' + record.dynamodb.NewImage.address.S,
}],
is_system: false
},
{
id: 664225,
name: "TxAssetID",
values: [{
value: record.dynamodb.NewImage.TxAssetID.S
}],
is_system: false
},
{
id: 664227,
name: "countMiners",
values: [{
value: record.dynamodb.NewImage.countMiners.N
}],
is_system: false
},
{
id: 664381,
name: "referal",
values: [{
value: record.dynamodb.NewImage.referal.S
}],
is_system: false
},
]
}]);
});
console.log("Stop Insert");
}
});
}