Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

feat: Add SMS report to the conversation history

Clémence Lesné4d8372276915
diff --git a/main.py b/main.py
index deab6d7..aaf7994 100644
--- a/main.py
+++ b/main.py
@@ -878,6 +878,10 @@ async def handle_hangup(client: CallConnectionClient, call: CallModel) -> None:
except ResourceNotFoundError:
_logger.debug(f"Call already hung up ({call.id})")
+ call.messages.append(
+ CallMessageModel(content="Customer ended the call.", persona=CallPersona.HUMAN)
+ )
+
content = await gpt_completion(LLMPrompt.SMS_SUMMARY_SYSTEM, call)
_logger.info(f"SMS report ({call.id}): {content}")
@@ -893,10 +897,22 @@ async def handle_hangup(client: CallConnectionClient, call: CallModel) -> None:
_logger.info(
f"SMS report sent {response.message_id} to {response.to} ({call.id})"
)
+ call.messages.append(
+ CallMessageModel(
+ content=f"SMS report sent to {response.to}: {content}",
+ persona=CallPersona.ASSISTANT,
+ )
+ )
else:
_logger.warn(
f"Failed SMS to {response.to}, status {response.http_status_code}, error {response.error_message} ({call.id})"
)
+ call.messages.append(
+ CallMessageModel(
+ content=f"Failed to send SMS report to {response.to}: {response.error_message}",
+ persona=CallPersona.ASSISTANT,
+ )
+ )
except Exception:
_logger.warn(f"Failed SMS to {call.phone_number} ({call.id})", exc_info=True)