-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathlookup.js
43 lines (37 loc) · 1.06 KB
/
lookup.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
import { getInfoForUser, initBot, airFind, transcript } from '../../utils'
const interactionSOMLookup = async (bot = initBot(), message) => {
const taggedUserID = (message.text.match(/<@([a-zA-Z0-9]*)|/) || [])[1]
if (!taggedUserID) {
console.log('No tagged user!')
return // do something if we don't tag a user
}
const { person, slackUser } = await getInfoForUser(taggedUserID)
if (slackUser.is_restricted) {
bot.replyPrivateDelayed(
message,
transcript('som.lookup.stillGuest', { user: taggedUserID })
)
return
}
const record = await airFind(
'Join Requests',
`AND(NOT(Approver=BLANK()),{Email Address}='${person.fields['Email']}')`,
null,
{ base: 'som' }
)
if (record) {
bot.replyPrivateDelayed(
message,
transcript('som.lookup.found', {
user: taggedUserID,
approver: record.fields['Approver'],
})
)
} else {
bot.replyPrivateDelayed(
message,
transcript('som.lookup.notFound', { user: taggedUserID })
)
}
}
export default interactionSOMLookup