AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(backend): Enable Ayrshare Instagram support (#10504)
Swiftyb429505c14ae
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_instagram.py b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_instagram.pyindex 77337a9568..bbf5ed5e12 100644--- a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_instagram.py+++ b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_instagram.py@@ -1,3 +1,5 @@+from typing import Any+from backend.integrations.ayrshare import PostIds, PostResponse, SocialPlatformfrom backend.sdk import (Block,@@ -33,40 +35,46 @@ class PostToInstagramBlock(Block):)# Instagram-specific options- is_story: bool = SchemaField(+ is_story: bool | None = SchemaField(description="Whether to post as Instagram Story (24-hour expiration)",- default=False,+ default=None,advanced=True,)- share_reels_feed: bool = SchemaField(++ # ------- REELS OPTIONS -------+ share_reels_feed: bool | None = SchemaField(description="Whether Reel should appear in both Feed and Reels tabs",- default=True,+ default=None,advanced=True,)- audio_name: str = SchemaField(+ audio_name: str | None = SchemaField(description="Audio name for Reels (e.g., 'The Weeknd - Blinding Lights')",- default="",+ default=None,advanced=True,)- thumbnail: str = SchemaField(- description="Thumbnail URL for Reel video", default="", advanced=True+ thumbnail: str | None = SchemaField(+ description="Thumbnail URL for Reel video", default=None, advanced=True)- thumbnail_offset: int = SchemaField(+ thumbnail_offset: int | None = SchemaField(description="Thumbnail frame offset in milliseconds (default: 0)",default=0,advanced=True,)++ # ------- POST OPTIONS -------+alt_text: list[str] = SchemaField(- description="Alt text for each media item (up to 1,000 chars each, accessibility feature)",+ description="Alt text for each media item (up to 1,000 chars each, accessibility feature), each item in the list corresponds to a media item in the media_urls list",default_factory=list,advanced=True,)- location_id: str = SchemaField(++ location_id: str | None = SchemaField(description="Facebook Page ID or name for location tagging (e.g., '7640348500' or '@guggenheimmuseum')",- default="",+ default=None,advanced=True,)- user_tags: list[InstagramUserTag] = SchemaField(+ user_tags: list[dict[str, Any]] = SchemaField(description="List of users to tag with coordinates for images",default_factory=list,advanced=True,@@ -76,9 +84,9 @@ class PostToInstagramBlock(Block):default_factory=list,advanced=True,)- auto_resize: bool = SchemaField(+ auto_resize: bool | None = SchemaField(description="Auto-resize images to 1080x1080px for Instagram",- default=False,+ default=None,advanced=True,)@@ -88,9 +96,8 @@ class PostToInstagramBlock(Block):def __init__(self):super().__init__(- disabled=True,id="89b02b96-a7cb-46f4-9900-c48b32fe1552",- description="Post to Instagram using Ayrshare",+ description="Post to Instagram using Ayrshare. Requires a Business or Creator Instagram Account connected with a Facebook Page",categories={BlockCategory.SOCIAL},block_type=BlockType.AYRSHARE,input_schema=PostToInstagramBlock.Input,@@ -127,6 +134,17 @@ class PostToInstagramBlock(Block):yield "error", "Instagram supports a maximum of 3 collaborators"return+ # Validate that if any reel option is set, all required reel options are set+ reel_options = [+ input_data.share_reels_feed,+ input_data.audio_name,+ input_data.thumbnail,+ ]++ if any(reel_options) and not all(reel_options):+ yield "error", "When posting a reel, all reel options must be set: share_reels_feed, audio_name, and either thumbnail or thumbnail_offset"+ return+# Count hashtags and mentionshashtag_count = input_data.post.count("#")mention_count = input_data.post.count("@")@@ -160,7 +178,7 @@ class PostToInstagramBlock(Block):if input_data.thumbnail:instagram_options["thumbNail"] = input_data.thumbnail- elif input_data.thumbnail_offset > 0:+ elif input_data.thumbnail_offset and input_data.thumbnail_offset > 0:instagram_options["thumbNailOffset"] = input_data.thumbnail_offset# Alt text@@ -180,14 +198,19 @@ class PostToInstagramBlock(Block):if input_data.user_tags:user_tags_list = []for tag in input_data.user_tags:- tag_dict: dict[str, float | str] = {"username": tag.username}- if tag.x is not None and tag.y is not None:+ try:+ tag_obj = InstagramUserTag(**tag)+ except Exception as e:+ yield "error", f"Invalid user tag: {e}, tages need to be a dictionary with a 3 items: username (str), x (float) and y (float)"+ return+ tag_dict: dict[str, float | str] = {"username": tag_obj.username}+ if tag_obj.x is not None and tag_obj.y is not None:# Validate coordinates- if not (0.0 <= tag.x <= 1.0) or not (0.0 <= tag.y <= 1.0):- yield "error", f"User tag coordinates must be between 0.0 and 1.0 (user: {tag.username})"+ if not (0.0 <= tag_obj.x <= 1.0) or not (0.0 <= tag_obj.y <= 1.0):+ yield "error", f"User tag coordinates must be between 0.0 and 1.0 (user: {tag_obj.username})"return- tag_dict["x"] = tag.x- tag_dict["y"] = tag.y+ tag_dict["x"] = tag_obj.x+ tag_dict["y"] = tag_obj.yuser_tags_list.append(tag_dict)instagram_options["userTags"] = user_tags_listdiff --git a/autogpt_platform/backend/backend/server/integrations/router.py b/autogpt_platform/backend/backend/server/integrations/router.pyindex ef5de6cd47..bc18b3cd18 100644--- a/autogpt_platform/backend/backend/server/integrations/router.py+++ b/autogpt_platform/backend/backend/server/integrations/router.py@@ -623,7 +623,7 @@ async def get_ayrshare_sso_url(# SocialPlatform.FACEBOOK,SocialPlatform.TWITTER,SocialPlatform.LINKEDIN,- # SocialPlatform.INSTAGRAM,+ SocialPlatform.INSTAGRAM,SocialPlatform.YOUTUBE,# SocialPlatform.REDDIT,# SocialPlatform.TELEGRAM,