-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (68 loc) · 2.28 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
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
const { Requester, Validator } = require('@chainlink/external-adapter')
const { getDescriptionValue } = require('./scrapper')
// Define custom error scenarios for the API.
// Return true for the adapter to retry.
const customError = (data) => {
if (data.Response === 'Error') return true
return false
}
//The customParams by the data I need
//The id of the instagram post
//The hash of the instagram post(ID to string)
//The access_token of the user, which will give me validating Its instagram account on the platform
//by the authentication tool instagram provides
const customParams = {
id: ['postId'],
hash: ['hashToVerify']
}
const createRequest = (input, callback) => {
// The Validator helps you validate the Chainlink request data
const validator = new Validator(input, customParams)
const jobRunID = validator.validated.id
const hash = validator.validated.data.hash
const id = validator.validated.data.id
const instagramUrl = `https://www.instagram.com/p/${id}/`
console.log('instagramUrl:', instagramUrl)
console.log('requestUrl:', instagramUrl)
getDescriptionValue(instagramUrl)
.then(descriptionValue => {
console.log('Valor de la etiqueta meta "description":', descriptionValue);
var result = false;
if(descriptionValue.includes(hash)){
result = true;
}
callback(200,
{ jobRunID: jobRunID, data: { result: result } })
})
.catch(error => {
console.error(error);
});
}
// This is a wrapper to allow the function to work with
// GCP Functions
exports.gcpservice = (req, res) => {
createRequest(req.body, (statusCode, data) => {
res.status(statusCode).send(data)
})
}
// This is a wrapper to allow the function to work with
// AWS Lambda
exports.handler = (event, context, callback) => {
createRequest(event, (statusCode, data) => {
callback(null, data)
})
}
// This is a wrapper to allow the function to work with
// newer AWS Lambda implementations
exports.handlerv2 = (event, context, callback) => {
createRequest(JSON.parse(event.body), (statusCode, data) => {
callback(null, {
statusCode: statusCode,
body: JSON.stringify(data),
isBase64Encoded: false
})
})
}
// This allows the function to be exported for testing
// or for running in express
module.exports.createRequest = createRequest