← back to Norma
instagram-agent fully LIVE: real token installed, monitor/discover/report un-stubbed (Steve-authorized), Graph v21 metrics fixed
b9d1c049c3cca9655828e0979191fac3d2aebe13 · 2026-07-23 08:20:56 -0700 · Steve Abrams
Files touched
M agents/instagram-agent/skills/monitor.jsM agents/instagram-agent/skills/report.js
Diff
commit b9d1c049c3cca9655828e0979191fac3d2aebe13
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Thu Jul 23 08:20:56 2026 -0700
instagram-agent fully LIVE: real token installed, monitor/discover/report un-stubbed (Steve-authorized), Graph v21 metrics fixed
---
agents/instagram-agent/skills/monitor.js | 30 ++++++++--------
agents/instagram-agent/skills/report.js | 60 +++++++++++++++-----------------
2 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/agents/instagram-agent/skills/monitor.js b/agents/instagram-agent/skills/monitor.js
index c835a09..1efd7fb 100644
--- a/agents/instagram-agent/skills/monitor.js
+++ b/agents/instagram-agent/skills/monitor.js
@@ -66,21 +66,23 @@ module.exports = async function monitor(params) {
const accessToken = process.env.IG_ACCESS_TOKEN;
// Fetch insights
- // valid metric set per Graph v21+ (impressions/email_contacts deprecated)
- const metrics = 'reach,follower_count,profile_views,website_clicks';
- const insightsUrl = `https://graph.facebook.com/v19.0/${igUserId}/insights?metric=${metrics}&period=${period}&access_token=${accessToken}`;
-
- const insightsResponse = await fetch(insightsUrl);
- const insightsData = await insightsResponse.json();
-
- if (insightsData.error) {
- throw new Error(`Instagram API error (insights): ${insightsData.error.message}`);
- }
-
+ // Graph v21+: impressions/email_contacts deprecated; profile_views and
+ // website_clicks require metric_type=total_value (separate call)
const insights = {};
- for (const entry of insightsData.data) {
- const value = entry.values?.[entry.values.length - 1]?.value || 0;
- insights[entry.name] = value;
+ const calls = [
+ `https://graph.facebook.com/v21.0/${igUserId}/insights?metric=reach,follower_count&period=${period}&access_token=${accessToken}`,
+ `https://graph.facebook.com/v21.0/${igUserId}/insights?metric=profile_views,website_clicks&metric_type=total_value&period=${period}&access_token=${accessToken}`,
+ ];
+ for (const url of calls) {
+ const resp = await fetch(url);
+ const data = await resp.json();
+ if (data.error) {
+ throw new Error(`Instagram API error (insights): ${data.error.message}`);
+ }
+ for (const entry of data.data) {
+ insights[entry.name] = entry.total_value?.value ??
+ (entry.values?.[entry.values.length - 1]?.value || 0);
+ }
}
// Fetch account info
diff --git a/agents/instagram-agent/skills/report.js b/agents/instagram-agent/skills/report.js
index de731c2..af4fac6 100644
--- a/agents/instagram-agent/skills/report.js
+++ b/agents/instagram-agent/skills/report.js
@@ -67,36 +67,34 @@ module.exports = async function report(params) {
// 3. Query sdcc_agent_actions for recent actions by this agent
// 4. Push aggregated report to Pulse via shared/pulse-reporter
//
- // const monitor = require('./monitor');
- // const discover = require('./discover');
- // const { reportAgentStatus } = require('../../shared/pulse-reporter');
- // const { getActionSummary } = require('../../shared/audit-logger');
- //
- // const insights = await monitor({ period: 'day' });
- // const recentMedia = await discover({ limit: 10 });
- // const actionSummary = await getActionSummary(AGENT, hoursBack);
- //
- // const reportData = {
- // agent: AGENT,
- // platform: PLATFORM,
- // credentials_configured: true,
- // period_hours: hoursBack,
- // insights: insights.insights,
- // account: insights.account,
- // recent_media: recentMedia.media,
- // actions: actionSummary,
- // uptime: process.uptime(),
- // simulated: false,
- // reported_at: new Date().toISOString(),
- // };
- //
- // await reportAgentStatus(AGENT, {
- // state: 'running',
- // uptime: process.uptime(),
- // stats: reportData.insights,
- // });
- //
- // return reportData;
+ const monitor = require('./monitor');
+ const discover = require('./discover');
+ const { reportAgentStatus } = require('../../shared/pulse-reporter');
+ const { getActionSummary } = require('../../shared/audit-logger');
+
+ const insights = await monitor({ period: 'day' });
+ const recentMedia = await discover({ limit: 10 });
+ const actionSummary = await getActionSummary(AGENT, hoursBack);
+
+ const reportData = {
+ agent: AGENT,
+ platform: PLATFORM,
+ credentials_configured: true,
+ period_hours: hoursBack,
+ insights: insights.insights,
+ account: insights.account,
+ recent_media: recentMedia.media,
+ actions: actionSummary,
+ uptime: process.uptime(),
+ simulated: false,
+ reported_at: new Date().toISOString(),
+ };
+
+ await reportAgentStatus(AGENT, {
+ state: 'running',
+ uptime: process.uptime(),
+ stats: reportData.insights,
+ });
- return { error: 'Real API call not yet enabled. Uncomment the code above.' };
+ return reportData;
};
← be52823 auto-save: 2026-07-23T08:19:35 (2 files) — agents/instagram-
·
back to Norma
·
(newest)