-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup_alert.lua
More file actions
127 lines (112 loc) · 4.24 KB
/
signup_alert.lua
File metadata and controls
127 lines (112 loc) · 4.24 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
125
126
127
function signup_alert(p)
if(p == nil) then
return {
ref = "signup_alert",
name = "Alert on signup",
description = "This trigger will automatically send alerts or notifications based on customer sigenup",
priority = 0,
triggerType = "POST_CREATE",
triggerOptions = {"USER"},
api = "TRIGGER",
version = 1,
}
end
print("========== 1 ==========")
local toEmail = checkBeKey(p.beUUID, 'SIGNUP_LOGIN_EMAIL')
if(toEmail.success) then
print("========== ALERT ON SINGUP ==========")
local beMail = getBEMail(p.beUUID)
local message = "Customer " .. p.input:getFirstName() .. " " .. p.input:getLastName() .. "has successfully signed up!"
print('Sending SignUp email to :' .. toEmail.keyValue)
sendMail(toEmail.keyValue, beMail, message)
print("========== ALERT ON SINGUP COMPLETE==========")
end
return { exitState = "SUCCESS" }
end
function login_alert(p)
if(p == nil) then
return {
ref = "login_alert",
name = "Alert on login",
description = "This trigger will automatically send mail to user after h",
priority = 0,
triggerType = "POST_AUTH",
triggerOptions = {"SUCCESS"},
api = "TRIGGER",
version = 1,
}
end
local toEmail = checkBeKey(p.beUUID, 'SIGNUP_LOGIN_EMAIL')
if(toEmail.success) then
print("========== ALERT ON LOGIN ==========")
local beMail = getBEMail(p.beUUID)
if not (string.find(p.input, beMail) or string.find(p.input, "jobs")) then
local userEmail = p.user:getEmail()
local message = "User " .. p.user:getFirstName() .. " " .. p.user:getLastName() .. " has successfully logged in."
print('Sending login email to : ' .. toEmail.keyValue)
sendMail(toEmail.keyValue, beMail, message)
end
print("========== ALERT ON LOGIN ==========")
end
return { exitState = "SUCCESS" }
end
function sendMail(toEmail, beMail, msg)
local emailHelper = new("FDLEmailHelper")
emailHelper:sendEmail(toEmail, beMail, beMail, nil, nil, "Signup-Login Alert", msg, nil)
end
function getUserEmail(customerUUID)
local searchFilter = new("SearchFilter")
local filterCondition1 = new("FilterCondition")
filterCondition1:setField('resourceuuid')
filterCondition1:setValue({customerUUID})
filterCondition1:setCondition(new("Condition","IS_EQUAL_TO"))
searchFilter:addCondition(filterCondition1)
local customer = adminAPI:listResources(searchFilter,nil,new("ResourceType","CUSTOMER"))
local userEmail = customer:getList():get(0):getUsers():get(0):getEmail()
return userEmail
end
function getBEMail(beUUID)
local searchFilter = new("SearchFilter")
local filterCondition1 = new("FilterCondition")
filterCondition1:setField('billingentityuuid')
filterCondition1:setValue({beUUID})
filterCondition1:setCondition(new("Condition","IS_EQUAL_TO"))
local filterCondition2 = new("FilterCondition")
filterCondition2:setField('status')
filterCondition2:setValue({"ADMIN"})
filterCondition2:setCondition(new("Condition","IS_EQUAL_TO"))
searchFilter:addCondition(filterCondition1)
searchFilter:addCondition(filterCondition2)
local customer = adminAPI:listResources(searchFilter,nil,new("ResourceType","CUSTOMER"))
local userEmail = customer:getList():get(0):getUsers():get(0):getEmail()
return userEmail
end
function checkBeKey(beUUID, resourceKeyName)
local searchFilter = new("SearchFilter")
local filterCondition1 = new("FilterCondition")
filterCondition1:setField('resourceuuid')
filterCondition1:setValue({beUUID})
filterCondition1:setCondition(new("Condition","IS_EQUAL_TO"))
local filterCondition2 = new("FilterCondition")
filterCondition2:setField('resourcekey.name')
filterCondition2:setValue({resourceKeyName})
filterCondition2:setCondition(new("Condition","IS_EQUAL_TO"))
searchFilter:addCondition(filterCondition1)
searchFilter:addCondition(filterCondition2)
local billingEntity = adminAPI:listResources(searchFilter,nil,new("ResourceType","BILLING_ENTITY"))
if(billingEntity:getList():size() == 1) then
for i = 0, billingEntity:getList():get(0):getResourceKey():size() - 1, 1 do
if(billingEntity:getList():get(0):getResourceKey():get(i):getName() == resourceKeyName) then
return {success = true, keyValue = billingEntity:getList():get(0):getResourceKey():get(i):getValue() }
end
end
else
return {success = false}
end
end
function register()
return {
"signup_alert",
--"login_alert"
}
end