Skip to content

Commit 6edf5dc

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(instagram): preserve insight metrics in workflow edits
1 parent 0f49ed3 commit 6edf5dc

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

apps/sim/blocks/blocks/instagram.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,19 @@ describe('InstagramBlock', () => {
9494
buildParams({ operation: 'instagram_get_account_insights', period: 'week' })
9595
).toThrow('Instagram account insights period must be day or lifetime')
9696
})
97+
98+
it('maps the provider-local insight field to the tool metrics parameter', () => {
99+
const metricsSubBlock = InstagramBlock.subBlocks.find(
100+
(subBlock) => subBlock.id === 'insightMetrics'
101+
)
102+
103+
expect(metricsSubBlock?.type).toBe('short-input')
104+
expect(InstagramBlock.subBlocks.some((subBlock) => subBlock.id === 'metrics')).toBe(false)
105+
expect(
106+
buildParams({
107+
operation: 'instagram_get_media_insights',
108+
insightMetrics: 'reach,views',
109+
})
110+
).toMatchObject({ metrics: 'reach,views', insightMetrics: undefined })
111+
})
97112
})

apps/sim/blocks/blocks/instagram.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ const OPERATION_PARAM_KEYS: Record<string, readonly string[]> = {
4545
instagram_send_text_message: ['igUserId', 'recipientId', 'message'],
4646
instagram_get_account_insights: [
4747
'igUserId',
48-
'metrics',
48+
'insightMetrics',
4949
'period',
5050
'since',
5151
'until',
5252
'metricType',
5353
'breakdown',
5454
'timeframe',
5555
],
56-
instagram_get_media_insights: ['mediaId', 'metrics'],
56+
instagram_get_media_insights: ['mediaId', 'insightMetrics'],
5757
}
5858

5959
const INSTAGRAM_TOOL_IDS = new Set(Object.keys(OPERATION_PARAM_KEYS))
@@ -64,6 +64,7 @@ const INSTAGRAM_OPERATION_INPUT_KEYS = new Set([
6464
'media',
6565
'carouselMedia',
6666
...Object.values(OPERATION_PARAM_KEYS).flat(),
67+
'metrics',
6768
])
6869

6970
const NUMERIC_PARAM_KEYS = new Set(['limit', 'thumbOffset'])
@@ -479,7 +480,7 @@ export const InstagramBlock: BlockConfig<InstagramResponse> = {
479480
required: { field: 'operation', value: 'instagram_send_text_message' },
480481
},
481482
{
482-
id: 'metrics',
483+
id: 'insightMetrics',
483484
title: 'Metrics',
484485
type: 'short-input',
485486
placeholder: 'Comma-separated metrics (e.g. reach,views,likes)',
@@ -715,7 +716,9 @@ Return ONLY the timestamp or date - no explanations, no extra text.`,
715716
const value = params[key]
716717
if (value === undefined || value === null || value === '') continue
717718

718-
if (NUMERIC_PARAM_KEYS.has(key)) {
719+
if (key === 'insightMetrics') {
720+
result.metrics = value
721+
} else if (NUMERIC_PARAM_KEYS.has(key)) {
719722
result[key] = Number(value)
720723
} else if (BOOLEAN_PARAM_KEYS.has(key)) {
721724
result[key] = value === true || value === 'true'
@@ -777,7 +780,7 @@ Return ONLY the timestamp or date - no explanations, no extra text.`,
777780
conversationId: { type: 'string', description: 'DM conversation ID' },
778781
messageId: { type: 'string', description: 'DM message ID' },
779782
recipientId: { type: 'string', description: 'DM recipient Instagram-scoped ID' },
780-
metrics: { type: 'string', description: 'Comma-separated insight metrics' },
783+
insightMetrics: { type: 'string', description: 'Comma-separated insight metrics' },
781784
period: { type: 'string', description: 'Account insight period: day or lifetime' },
782785
since: { type: 'string', description: 'Account insights range start' },
783786
until: { type: 'string', description: 'Account insights range end' },

0 commit comments

Comments
 (0)