-
Notifications
You must be signed in to change notification settings - Fork 0
/
verifyNumber.js
39 lines (34 loc) · 954 Bytes
/
verifyNumber.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
import request from "request-promise-native";
const AUTHY_API_KEY = process.env.AUTHY_API_KEY;
exports.handler = function(event, context, callback) {
const requestBody = JSON.parse(event.body);
const countryCode = requestBody.countryCode;
const phoneNumber = requestBody.phoneNumber;
request({
method: "POST",
uri: "https://api.authy.com/protected/json/phones/verification/start",
headers: {
"X-Authy-API-Key": AUTHY_API_KEY
},
body: {
country_code: countryCode,
phone_number: phoneNumber,
via: "sms"
},
json: true
})
.then(() => {
console.log("Verification Pending:", countryCode, phoneNumber);
callback(null, {
statusCode: 200,
body: JSON.stringify({ ok: true })
});
})
.catch((error) => {
console.log("Error:", error);
callback(null, {
statusCode: 200,
body: JSON.stringify({ ok: false })
});
});
};