-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (40 loc) · 1.3 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
const callGoDaddy = require('./callGoDaddy');
const checkFromResponse = require('./availabiltyChecker');
const sendMail = require('./mailHandler');
const PromiseallSettled =require('./promeiseAllPolyfill');
// const list = require('domainList.json');
require('dotenv').config();
const list={
"main":"google.com"
}
const testUrl = "https://api.godaddy.com/v1/domains/available"
const fromMail="masterakshata@gmail.com"
const toMail=fromMail
const checker=async (data,context)=>{
try {
const [success,response]= await callGoDaddy(process.env.GO_DADDY_KEY,process.env.GO_DADDY_SECRET,list,testUrl);
//console.log(response)
if(success){
let mailsToBeSent=[]
const availableDomains= checkFromResponse(response);
//console.log(availableDomains)
if(availableDomains.length>0){
availableDomains.forEach(domain=>{
mailsToBeSent.push(sendMail(domain,fromMail,toMail))
console.log("mail sent")
})
PromiseallSettled(mailsToBeSent).then().catch(e=>{
console.log(e)
})
}
}
} catch (error) {
console.log(error)
}
}
//for development debugging
checker(1,2).then(a=>{
console.log('pls work')
})
// console.log(res);
exports.checker=checker;