chatResponse = {
const token =
TWILIO_AUTH_TOKEN || whatsappEvent.ctx.secrets["TWILIO_AUTH_TOKEN"];
if (msg === "chart") {
fetch(
`https://api.twilio.com/2010-04-01/Accounts/${TWILIO_ACCOUNT_SID}/Messages.json`,
{
method: "POST",
body: new URLSearchParams(
Object.entries({
From: "whatsapp:+14155238886",
To: whatsappIncoming.From,
Body: "Your chart:",
MediaUrl: pngLink.href
})
).toString(),
headers: {
"content-type": "application/x-www-form-urlencoded",
authorization: `Basic ${btoa(TWILIO_ACCOUNT_SID + ":" + token)}`
}
}
);
return "Sending chart";
} else {
fetch(
`https://api.twilio.com/2010-04-01/Accounts/${TWILIO_ACCOUNT_SID}/Messages.json`,
{
method: "POST",
body: new URLSearchParams(
Object.entries({
From: "whatsapp:+14155238886",
To: whatsappIncoming.From,
Body: `The sensor's last payload is ${JSON.stringify(
latest["dev:864475046457429"].body
)}`
})
).toString(),
headers: {
"content-type": "application/x-www-form-urlencoded",
authorization: `Basic ${btoa(TWILIO_ACCOUNT_SID + ":" + token)}`
}
}
);
return "Sending latest payload";
}
}