{} Extract FB IDs {}
const entries = $json.body.entry || [];
let results = [ ];
for (const entry of entries) {
const messagingEvents = entry.messaging || [ ];
for (const event of messagingEvents) {
results.push({
sender_id: event.sender?.id || null,
recipient_id: event.recipient?.id || null,
message_text: event.message?.text || null,
timestamp: event.timestamp || Date.now()
});
}
}
return results.map(r => ({ json: r }));
{} Audio Binary Data {}
// n8n Function node
// Assumes incoming items have binary data under binaryKey 'data' (change if different)
const binaryKey = 'data';
for (let i = 0; i < items.length; i++) {
if (items[i].binary && items[i].binary[binaryKey]) {
// ensure the binary object exists
items[i].binary[binaryKey].mimeType = 'audio/mpeg';
// optionally adjust fileName extension if needed
if (items[i].binary[binaryKey].fileName && !items[i].binary[binaryKey].fileName.endsWith('.mp3')) {
items[i].binary[binaryKey].fileName = items[i].binary[binaryKey].fileName.split('.').slice(0, -1).join('.') + '.mp3';
}
}
}
return items;
Output Parser {}
const rawText = $input.item.json.text;
let parsed;
const start = rawText.indexOf('```');
const end = rawText.lastIndexOf('```');
if (start !== -1 && end !== -1 && start !== end) {
let jsonString = rawText.substring(start + 3, end).trim();
if (jsonString.startsWith('json')) {
jsonString = jsonString.substring(4).trim();
}
parsed = JSON.parse(jsonString);
} else {
const jsonStart = rawText.indexOf('{');
const jsonEnd = rawText.lastIndexOf('}');
if (jsonStart !== -1 && jsonEnd !== -1) {
parsed = JSON.parse(rawText.substring(jsonStart, jsonEnd + 1));
} else {
return {
error: "Could not find JSON in response",
original: rawText
};
}
}
return {
subject: parsed.subject || parsed.Subject || "",
body: parsed.body || parsed.Body || parsed.email_body || parsed.Message || parsed.message || ""
};
Output Parser {}
// This loop ensures the code runs for every item in the current execution
return items.map(item => {
// 1. Get the data from the previous "Approval data" node
// We use item.json.execution_id to match your Set node exactly
const rawExecutionData = item.json.execution_id || "";
const feedbackText = item.json.feedback || "";
// 2. Split "5051, true" by the comma
const parts = rawExecutionData.split(',').map(p => p.trim());
// 3. Return the structured object n8n needs
return {
json: {
id: "",
approval: parts[1] || "", // This will be "true" or "false"
feedback: feedbackText, // This will be your Telegram message text
execution_id: parts[0] || "" // This will be "5051"
}
};
});
Extract Approval Data {}
// This loop ensures the code runs for every item in the current execution
return items.map(item => {
// 1. Get the data from the previous "Approval data" node
// We use item.json.execution_id to match your Set node exactly
const rawExecutionData = item.json.execution_id || "";
const feedbackText = item.json.feedback || "";
// 2. Split "5051, true" by the comma
const parts = rawExecutionData.split(',').map(p => p.trim());
// 3. Return the structured object n8n needs
return {
json: {
id: "",
approval: parts[1] || "", // This will be "true" or "false"
feedback: feedbackText, // This will be your Telegram message text
execution_id: parts[0] || "" // This will be "5051"
}
};
});
