Skip to content

Commit

Permalink
Merge branch 'master' into glossary_new
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderGi committed Sep 19, 2023
2 parents 0523eb9 + b6678c2 commit e86c01b
Show file tree
Hide file tree
Showing 32 changed files with 2,773 additions and 1,715 deletions.
38 changes: 25 additions & 13 deletions bots/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ class Meta:
widgets = {
"platform": forms.Select(
attrs={
"--hideshow-fields": "fb_page_id,fb_page_name,fb_page_access_token,ig_account_id,ig_username,wa_phone_number,wa_phone_number_id,slack_channel_id,slack_channel_hook_url,slack_access_token",
"--hideshow-fields": "fb_page_id,fb_page_name,fb_page_access_token,ig_account_id,ig_username,wa_phone_number,wa_phone_number_id,slack_team_id,slack_team_name,slack_channel_id,slack_channel_name,slack_channel_hook_url,slack_access_token,slack_read_receipt_msg,slack_create_personal_channels",
"--show-on-1": "fb_page_id,fb_page_name,fb_page_access_token",
"--show-on-2": "fb_page_id,fb_page_name,fb_page_access_token,ig_account_id,ig_username",
"--show-on-3": "wa_phone_number,wa_phone_number_id",
"--show-on-4": "slack_channel_id,slack_channel_hook_url,slack_access_token",
"--show-on-4": "slack_team_id,slack_team_name,slack_channel_id,slack_channel_name,slack_channel_hook_url,slack_access_token,slack_read_receipt_msg,slack_create_personal_channels",
},
),
}
Expand All @@ -93,13 +93,17 @@ class BotIntegrationAdmin(admin.ModelAdmin):
"fb_page_id",
"wa_phone_number",
"slack_channel_id",
"billing_account_uid",
]
list_display = [
"__str__",
"name",
"get_display_name",
"platform",
"wa_phone_number",
"created_at",
"updated_at",
"billing_account_uid",
"saved_run",
"analysis_run",
]
list_filter = ["platform"]
Expand All @@ -111,6 +115,7 @@ class BotIntegrationAdmin(admin.ModelAdmin):
readonly_fields = [
"fb_page_access_token",
"slack_access_token",
"slack_channel_hook_url",
"view_analysis_results",
"view_conversations",
"view_messsages",
Expand Down Expand Up @@ -142,9 +147,14 @@ class BotIntegrationAdmin(admin.ModelAdmin):
"ig_username",
"wa_phone_number",
"wa_phone_number_id",
"slack_team_id",
"slack_team_name",
"slack_channel_id",
"slack_channel_name",
"slack_channel_hook_url",
"slack_access_token",
"slack_read_receipt_msg",
"slack_create_personal_channels",
]
},
),
Expand All @@ -165,7 +175,6 @@ class BotIntegrationAdmin(admin.ModelAdmin):
"fields": [
"show_feedback_buttons",
"analysis_run",
"enable_analysis",
"view_analysis_results",
]
},
Expand Down Expand Up @@ -234,7 +243,7 @@ def view_analysis_results(self, bi: BotIntegration):
.order_by("-count")
.values_list(key, "count")
)
if val
if val is not None
]
for key in nested_keys
}
Expand Down Expand Up @@ -397,15 +406,15 @@ class MessageAdmin(admin.ModelAdmin):
"role",
"created_at",
"feedbacks",
"wa_delivered",
"msg_delivered",
]
readonly_fields = [
"conversation",
"role",
"content",
"display_content",
"created_at",
"wa_msg_id",
"platform_msg_id",
"saved_run",
"analysis_run",
"prev_msg_content",
Expand Down Expand Up @@ -435,7 +444,7 @@ def get_fieldsets(self, request, msg: Message = None):
"conversation",
"role",
"created_at",
"wa_msg_id",
"platform_msg_id",
]
},
),
Expand Down Expand Up @@ -480,16 +489,19 @@ def get_fieldsets(self, request, msg: Message = None):
)
return fieldsets

def wa_delivered(self, msg: Message):
def msg_delivered(self, msg: Message):
if (
# user messages are delivered already
msg.role != CHATML_ROLE_ASSISSTANT
or msg.conversation.bot_integration.platform != Platform.WHATSAPP
# we only have delivery status for whatsapp and slack
or msg.conversation.bot_integration.platform
not in [Platform.WHATSAPP, Platform.SLACK]
):
raise Message.DoesNotExist
return bool(msg.wa_msg_id)
return bool(msg.platform_msg_id)

wa_delivered.short_description = "Delivered"
wa_delivered.boolean = True
msg_delivered.short_description = "Delivered"
msg_delivered.boolean = True

def prev_msg_content(self, message: Message):
prev_msg = message.get_previous_by_created_at()
Expand Down
16 changes: 16 additions & 0 deletions bots/migrations/0038_remove_botintegration_enable_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.3 on 2023-09-13 15:18

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("bots", "0037_savedrun_parent_not_self"),
]

operations = [
migrations.RemoveField(
model_name="botintegration",
name="enable_analysis",
),
]
21 changes: 21 additions & 0 deletions bots/migrations/0039_botintegration_slack_read_receipt_msg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.5 on 2023-09-14 15:13

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("bots", "0038_remove_botintegration_enable_analysis"),
]

operations = [
migrations.AddField(
model_name="botintegration",
name="slack_read_receipt_msg",
field=models.TextField(
blank=True,
default="Results may take up to 1 minute, we appreciate your patience.",
help_text="Bot's Slack read receipt message - if set, and platform is Slack, the bot will send this message to mark the user message as read and then delete it when it has a response ready",
),
),
]
Loading

0 comments on commit e86c01b

Please sign in to comment.