new(whatsapp.gblib): FB Analytics.
This commit is contained in:
parent
292d396eeb
commit
614539a0b4
1 changed files with 106 additions and 109 deletions
|
@ -1547,18 +1547,15 @@ private async sendButtonList(to: string, buttons: string[]) {
|
|||
return 'No statistics available for WhatsApp templates.';
|
||||
}
|
||||
|
||||
let templateData;
|
||||
|
||||
try {
|
||||
// Step 1: Fetch latest template message statistics
|
||||
// Step 1: Fetch all templates ordered by creation time
|
||||
const statsResponse = await fetch(
|
||||
`https://graph.facebook.com/v20.0/${businessAccountId}/message_templates?` +
|
||||
`fields=id,name,status,language,quality_score,category,created_time,` +
|
||||
`message_sends_24h,message_sends_7d,message_sends_30d,` +
|
||||
`delivered_24h,delivered_7d,delivered_30d,` +
|
||||
`read_24h,read_7d,read_30d&` +
|
||||
`limit=1&` +
|
||||
`order=created_time_desc`, {
|
||||
`ordering=[{created_time: 'DESC'}]`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${userAccessToken}`
|
||||
}
|
||||
|
@ -1573,7 +1570,8 @@ private async sendButtonList(to: string, buttons: string[]) {
|
|||
throw new Error('No template statistics found');
|
||||
}
|
||||
|
||||
templateData = data.data[0];
|
||||
// Get the last template from the sorted data
|
||||
const templateData = data.data[data.data.length - 1];
|
||||
console.log('Latest template statistics retrieved:', templateData.name);
|
||||
|
||||
// Step 2: Calculate key metrics
|
||||
|
@ -1647,5 +1645,4 @@ Read Rate: ${metrics.readRate30d}%
|
|||
console.error('Error fetching latest WhatsApp template statistics:', error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
|
Loading…
Add table
Reference in a new issue