Idempotent guard for share
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0c55724caa
commit
aad3123121
@ -5,6 +5,7 @@ from .models import FacebookPageAssistant
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from pxy_neo4j.neo4j_connector import Neo4jDatabase
|
||||
from .storage_backends import Neo4jStorage, PostgresStorage
|
||||
from .models import FacebookPageAssistant, BotInteraction
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -73,6 +74,16 @@ class FacebookService:
|
||||
"""
|
||||
Posts a comment on a shared post and then on the original post.
|
||||
"""
|
||||
|
||||
# *Idempotency guard*:
|
||||
if BotInteraction.objects.filter(
|
||||
page__page_id=page_id,
|
||||
object_id=post_id,
|
||||
platform="Facebook"
|
||||
).exists():
|
||||
logger.info(f"Already commented on share {post_id}, skipping.")
|
||||
return None
|
||||
|
||||
# 1) Fetch token
|
||||
page_access_token = self._get_page_access_token(page_id)
|
||||
if not page_access_token:
|
||||
@ -122,16 +133,6 @@ class FacebookService:
|
||||
# 6) Post on original post
|
||||
if parent_id and shared:
|
||||
orig = self._post_facebook_comment(parent_id, bot_response, page_access_token)
|
||||
if orig:
|
||||
self._store_interaction(
|
||||
page_id = page_id,
|
||||
object_id = post_id,
|
||||
parent_object_id = parent_id,
|
||||
prompt = prompt,
|
||||
bot_response = bot_response,
|
||||
platform = "Facebook"
|
||||
)
|
||||
|
||||
return shared
|
||||
|
||||
# ─── Helper: prompt builder ────────────────────────────────────────────
|
||||
|
Loading…
x
Reference in New Issue
Block a user