Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions bots/migrations/0104_conversation_platform_medium.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.1.3 on 2025-06-19 13:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("bots", "0103_alter_botintegration_public_visibility"),
]

operations = [
migrations.AddField(
model_name="conversation",
name="platform_medium",
field=models.CharField(
blank=True,
choices=[("SMS", "SMS"), ("VOICE", "Voice")],
default="",
help_text="Platform medium (Voice / SMS etc.)",
max_length=32,
),
),
]
13 changes: 13 additions & 0 deletions bots/models/convo_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class ConvoState(models.IntegerChoices):
ASK_FOR_FEEDBACK_THUMBS_DOWN = 2, "Ask for feedback (👎)"


class PlatformMedium(models.TextChoices):
SMS = "SMS", "SMS"
VOICE = "VOICE", "Voice"


class ConversationQuerySet(models.QuerySet):
def distinct_by_user_id(self) -> QuerySet["Conversation"]:
"""Get unique conversations"""
Expand Down Expand Up @@ -238,6 +243,14 @@ class Conversation(models.Model):
help_text="Twilio call sid (only used if each call is a new conversation)",
)

platform_medium = models.CharField(
max_length=32,
choices=PlatformMedium.choices,
blank=True,
default="",
help_text="Platform medium (Voice / SMS etc.)",
)

web_user_id = models.CharField(
max_length=512,
blank=True,
Expand Down
2 changes: 2 additions & 0 deletions daras_ai_v2/bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@ def build_system_vars(convo: Conversation, user_msg_id: str) -> tuple[dict, dict
variables["bot_twilio_phone_number"] = (
bi.twilio_phone_number and bi.twilio_phone_number.as_international
)
variables["platform_medium"] = convo.platform_medium

variables_schema = {var: {"role": "system"} for var in variables}
return variables, variables_schema

Expand Down
4 changes: 3 additions & 1 deletion daras_ai_v2/twilio_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from twilio.twiml import TwiML
from twilio.twiml.voice_response import VoiceResponse

from bots.models import BotIntegration, Platform, Conversation
from bots.models import BotIntegration, Conversation, Platform, PlatformMedium
from daras_ai_v2 import settings
from daras_ai_v2.bots import BotInterface, ReplyButton
from daras_ai_v2.fastapi_tricks import get_api_route_url
Expand All @@ -29,6 +29,7 @@ def __init__(self, data: dict):
bot_integration=bi,
twilio_phone_number=data["From"][0],
twilio_call_sid="",
platform_medium=PlatformMedium.SMS,
)[0]

self.bot_id = bi.twilio_phone_number.as_e164
Expand Down Expand Up @@ -175,6 +176,7 @@ def __init__(
audio_url: str = None,
):
self.convo = convo
self.convo.platform_medium = PlatformMedium.VOICE

self.bot_id = convo.bot_integration.twilio_phone_number.as_e164
self.user_id = convo.twilio_phone_number.as_e164
Expand Down