auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
if(steps.trigger.event.MediaUrl0) {
const fetch = require('node-fetch');
let img = steps.trigger.event.MediaUrl0;
console.log('going to process image: ',img);
let info = {
url:img
};
let resp = await fetch(`${process.env.MS_COG_EP}/vision/v3.1/analyze?visualFeatures=Categories,Description`,{
method:'POST',
headers:{
'Content-Type':'application/json',
'Accept':'application/json',
'Ocp-Apim-Subscription-Key': process.env.MS_COG_KEY
},
body:JSON.stringify(info)
});
let data = await resp.json();
this.text = `
I parsed your image and found: ${data.description.captions[0].text}
Here's other things I noted: ${data.description.tags.join(', ')}
`;
} else {
this.text = `
To use this service, please text a picture to me.
`
}
The destination phone number. Format with a '+' and country code e.g., +16175551212 (E.164 format).
A Twilio phone number (in E.164 format) or alphanumeric sender ID enabled for the type of message you wish to send. Phone numbers or short codes purchased from Twilio work here. You cannot (for example) spoof messages from your own cell phone number.
The text of the message you want to send, limited to 1600 characters.
async
(params, auths) => {
}
// Read the Twilio docs at https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource
const phone = require('phone');
// Parse the given number into its E.164 equivalent
// The E.164 phone number will be included in the first element
// of the array, but the array will be empty if parsing fails.
// See https://www.npmjs.com/package/phone
const toParsed = phone(params.To)
if (!toParsed.length) {
throw new Error(`Phone number ${params.To} couldn't be parsed as a valid number.`)
}
const fromParsed = phone(params.From)
if (!fromParsed.length) {
throw new Error(`Phone number ${params.From} couldn't be parsed as a valid number.`)
}
const data = {
To: toParsed[0],
From: fromParsed[0],
MessagingServiceSid: params.MessagingServiceSid,
Body: params.Body,
MediaUrl: params.MediaUrl,
}
const config = {
method: "post",
url: `https://api.twilio.com/2010-04-01/Accounts/${auths.twilio.AccountSid}/Messages.json`,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
auth: {
username: auths.twilio.Sid,
password: auths.twilio.Secret,
},
data: require("qs").stringify(data),
}
return await require("@pipedreamhq/platform").axios(this, config)