forked from smartsendercommunity/pipedrive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote.php
More file actions
124 lines (117 loc) · 4.7 KB
/
note.php
File metadata and controls
124 lines (117 loc) · 4.7 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
include('config.php');
$input = json_decode(file_get_contents("php://input"), true);
$log["url"] = $url;
if ($input["userId"] == NULL) {
$result["state"] = false;
$result["error"]["message"][] = "'userId' is missing";
} else {
if (file_exists('pdData/users.json')) {
$users = json_decode(file_get_contents('pdData/users.json'), true);
$contactId = $users[$input['userId']];
}
if ($contactId == NULL) {
$result["state"] = false;
$result["error"]["message"][] = "the contact was not created by this integration";
}
}
if ($input["text"] == NULL) {
if ($input["noteId"] == NULL || $input["comment"] == NULL) {
$onlyComment = true;
$result["state"] = false;
$result["error"]["message"][] = "'text' is missing";
}
}
if ($result["state"] === false) {
echo json_encode($result);
exit;
} else {
$result["state"] = true;
}
if ($onlyComment !== true) {
$note["person_id"] = $contactId;
$note["content"] = $input["text"];
if ($input["leadId"] != NULL) {
$note["lead_id"] = $input["leadId"];
if ($input["pinLead"]) {
$note["pinned_to_lead_flag"] = 1;
}
}
if ($input["dealId"] != NULL) {
$note["deal_id"] = $input["dealId"];
if ($input["pinDeal"]) {
$note["pinned_to_deal_flag"] = 1;
}
}
if ($input["pinContact"]) {
$note["pinned_to_person_flag"] = 1;
}
if ($input["noteId"] == NULL) {
// Создание примечания
$createNote = json_decode(send_request("https://api.pipedrive.com/v1/notes?api_token=".$pdKey, [], "POST", $note), true);
if ($createNote["success"] === false) {
sleep(1);
$createNote = json_decode(send_request("https://api.pipedrive.com/v1/notes?api_token=".$pdKey, [], "POST", $note), true);
}
if ($createNote["data"]["id"] != NULL) {
$noteId = $createNote["data"]["id"];
$logDescription[] = "Создано примечание: ".$noteId;
$result["noteId"] = $noteId;
$result["action"] = "create";
$result["result"] = $createNote;
} else {
$logData["state"] = "false";
$logDescription[] = "Ошибка создания примечания";
$result["state"] = false;
$result["result"] = $createNote;
}
$log["note"]["action"] = "create";
$log["note"]["send"] = $note;
$log["note"]["result"] = $createNote;
} else {
// Обновление примечания
$createNote = json_decode(send_request("https://api.pipedrive.com/v1/notes/".$input["noteId"]."?api_token=".$pdKey, [], "PUT", $note), true);
if ($createNote["success"] === false) {
sleep(1);
$createNote = json_decode(send_request("https://api.pipedrive.com/v1/notes/".$input["noteId"]."?api_token=".$pdKey, [], "PUT", $note), true);
}
if ($createNote["data"]["id"] != NULL) {
$noteId = $createNote["data"]["id"];
$logDescription[] = "Обновлено примечание: ".$noteId;
$result["noteId"] = $noteId;
$result["action"] = "update";
$result["result"] = $createNote;
} else {
$logData["state"] = "false";
$logDescription[] = "Ошибка обновления примечания";
$result["state"] = false;
$result["result"] = $createNote;
}
$log["note"]["action"] = "update";
$log["note"]["send"] = $note;
$log["note"]["result"] = $createNote;
}
}
if ($input["comment"] != NULL) {
$comment["content"] = $input["comment"];
$createComment = json_decode(send_request("https://api.pipedrive.com/v1/notes/".$noteId."/comments?api_token=".$pdKey, [], "POST", $comment), true);
if ($createComment["success"] === false) {
sleep(1);
$createComment = json_decode(send_request("https://api.pipedrive.com/v1/notes/".$noteId."/comments?api_token=".$pdKey, [], "POST", $comment), true);
}
if ($createComment["data"]["uuid"] != NULL) {
$commentId = $createComment["data"]["uuid"];
$logDescription[] = "Добавлен коментарий: ".$commentId;
$result["commentId"] = $commentId;
$result["comment"] = $createComment;
} else {
$logData["state"] = "false";
$logDescription[] = "Ошибка добавления коментария";
$result["state"] = false;
$result["comment"] = $createComment;
}
$log["comment"]["action"] = "update";
$log["comment"]["send"] = $comment;
$log["comment"]["result"] = $createComment;
}
echo json_encode($result);