From b77133fe836c79d48d99c8c5995a2e155a4fa660 Mon Sep 17 00:00:00 2001 From: Ekaropolus Date: Wed, 23 Jul 2025 01:04:11 -0600 Subject: [PATCH] Creation of Bot Interactio Table --- pxy_meta_pages/admin.py | 9 +++++ .../migrations/0004_botinteraction.py | 27 ++++++++++++++ pxy_meta_pages/models.py | 37 ++++++++++++++++++- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 pxy_meta_pages/migrations/0004_botinteraction.py diff --git a/pxy_meta_pages/admin.py b/pxy_meta_pages/admin.py index 12eb54d..fe215c9 100644 --- a/pxy_meta_pages/admin.py +++ b/pxy_meta_pages/admin.py @@ -94,3 +94,12 @@ from .models import EventType class EventTypeAdmin(admin.ModelAdmin): list_display = ("code", "label") search_fields = ("code", "label") + +from .models import BotInteraction + +@admin.register(BotInteraction) +class BotInteractionAdmin(admin.ModelAdmin): + list_display = ("page", "object_id", "parent_object_id", "platform", "created_at") + search_fields = ("object_id", "prompt", "bot_response") + list_filter = ("platform",) + diff --git a/pxy_meta_pages/migrations/0004_botinteraction.py b/pxy_meta_pages/migrations/0004_botinteraction.py new file mode 100644 index 0000000..27f8e30 --- /dev/null +++ b/pxy_meta_pages/migrations/0004_botinteraction.py @@ -0,0 +1,27 @@ +# Generated by Django 5.0.3 on 2025-07-23 06:01 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('pxy_meta_pages', '0003_eventtype_facebookevent'), + ] + + operations = [ + migrations.CreateModel( + name='BotInteraction', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('object_id', models.CharField(help_text='The Facebook post or comment ID that we commented on', max_length=100)), + ('parent_object_id', models.CharField(blank=True, help_text='If this comment was on a share, the original post’s ID', max_length=100, null=True)), + ('prompt', models.TextField(help_text='Exact prompt sent to OpenAI for this comment')), + ('bot_response', models.TextField(help_text='The text that the bot actually posted')), + ('platform', models.CharField(help_text="E.g. 'Facebook' or 'Facebook (Original Post)'", max_length=50)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('page', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bot_interactions', to='pxy_meta_pages.facebookpageassistant')), + ], + ), + ] diff --git a/pxy_meta_pages/models.py b/pxy_meta_pages/models.py index 860419d..460a4ce 100644 --- a/pxy_meta_pages/models.py +++ b/pxy_meta_pages/models.py @@ -64,4 +64,39 @@ class FacebookEvent(models.Model): def __str__(self): return f"{self.page.page_name}: {self.event_type.code} @ {self.timestamp:%Y-%m-%d %H:%M}" - \ No newline at end of file + + +class BotInteraction(models.Model): + """ + Stores each AI‐generated comment: which object we replied to, the prompt, + the response, and link back to the original (parent) post if any. + """ + page = models.ForeignKey( + FacebookPageAssistant, + on_delete=models.CASCADE, + related_name="bot_interactions" + ) + object_id = models.CharField( + max_length=100, + help_text="The Facebook post or comment ID that we commented on" + ) + parent_object_id = models.CharField( + max_length=100, + blank=True, + null=True, + help_text="If this comment was on a share, the original post’s ID" + ) + prompt = models.TextField( + help_text="Exact prompt sent to OpenAI for this comment" + ) + bot_response = models.TextField( + help_text="The text that the bot actually posted" + ) + platform = models.CharField( + max_length=50, + help_text="E.g. 'Facebook' or 'Facebook (Original Post)'" + ) + created_at = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return f"{self.page.page_name} → {self.object_id} @ {self.created_at:%Y-%m-%d %H:%M}" \ No newline at end of file