Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

fix(instagram): disconnect the channel on Meta checkpoint errors instead of failing every post

Gilad Resisi28730a0c1b2d
diff --git a/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts b/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
index b9eb4a2e9..8800a5ce9 100644
--- a/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
@@ -103,7 +103,7 @@ export class InstagramProvider
status: number
):
| {
- type: 'refresh-token' | 'bad-body' | 'retry';
+ type: 'refresh-token' | 'bad-body' | 'retry' | 'disconnect';
value: string;
}
| undefined {
@@ -330,6 +330,20 @@ export class InstagramProvider
};
}
+ // Meta put the account behind a checkpoint: the token is still valid, so a
+ // refresh cannot help and every post fails until the user logs in on
+ // Instagram and re-connects the channel.
+ if (
+ body.indexOf('You cannot access the app till you log in to') > -1 ||
+ body.indexOf('Session key is malformed') > -1
+ ) {
+ return {
+ type: 'disconnect' as const,
+ value:
+ 'Instagram requires you to log in at instagram.com and follow its instructions before posting can resume. After that, please reconnect this channel.',
+ };
+ }
+
if (body.indexOf('190,') > -1) {
return {
type: 'bad-body' as const,
diff --git a/libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts b/libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts
index 4c3261fbd..db023cdf5 100644
--- a/libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts
@@ -68,7 +68,10 @@ export class InstagramStandaloneProvider
body: string,
status: number
):
- | { type: 'refresh-token' | 'bad-body' | 'retry'; value: string }
+ | {
+ type: 'refresh-token' | 'bad-body' | 'retry' | 'disconnect';
+ value: string;
+ }
| undefined {
return instagramProvider.handleErrors(body, status);
}