Skip to content
Merged
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
2 changes: 1 addition & 1 deletion llmstack/apps/handlers/twilio_sms_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def run_app(self):
),
ActorConfig(
name='output', template_key='output', dependencies=['input'],
actor=OutputActor, kwargs={'template': '{{_inputs0._request}}'},
actor=OutputActor, kwargs={'template': '{{_inputs0}}'},
),
]
processor_actor_configs, processor_configs = self._get_processor_actor_configs()
Expand Down
12 changes: 12 additions & 0 deletions llmstack/client/src/components/apps/AppRunHistoryTimeline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { appsState } from "../../data/atoms";
import { axios } from "../../data/axios";
import { ReactComponent as DiscordIcon } from "../../assets/images/icons/discord.svg";
import { ReactComponent as SlackIcon } from "../../assets/images/icons/slack.svg";
import { ReactComponent as TwilioIcon } from "../../assets/images/icons/twilio.svg";
import "ace-builds/src-noconflict/mode-sh";
import "ace-builds/src-noconflict/theme-chrome";
import { profileFlagsState } from "../../data/atoms";
Expand Down Expand Up @@ -366,6 +367,17 @@ export function AppRunHistoryTimeline(props) {
{row.platform_data?.discord?.global_name}
</Box>
);
} else if (row.platform_data?.twilio?.requestor) {
return (<Box>
<SvgIcon
component={TwilioIcon}
fontSize="8"
sx={{
marginRight: "5px",
color: "#555",
verticalAlign: "middle",
}}/>{row.platform_data?.twilio?.requestor}
</Box>)
} else if (
row.request_user_email === null ||
row.request_user_email === ""
Expand Down
27 changes: 20 additions & 7 deletions llmstack/processors/providers/twilio/create_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@

logger = logging.getLogger(__name__)



class TwilioCreateMessageInput(ApiProcessorSchema):
_request: Optional[TwilioSmsWebhookRequest]
body: Optional[str]
to: Optional[str]

class TwilioCreateMessageOutput(ApiProcessorSchema):
response: dict
code: int = 200

class TwilioCreateMessageConfiguration(ApiProcessorSchema):
account_sid: Optional[str]
Expand Down Expand Up @@ -68,14 +65,23 @@ def _send_message(self, message: str, to_: str, from_: str, account_sid: str, au


def process(self) -> dict:
self._twilio_api_response = None
input = self._input.dict()
response = self._send_message(message=input['body'], to_=input['to'], from_=self._config.phone_number, account_sid=self._config.account_sid, auth_token=self._config.auth_token)

self._twilio_api_response = {
'code': response['code'],
'headers': response['headers'],
'text': response['text'],
}

async_to_sync(self._output_stream.write)(
TwilioCreateMessageOutput(response=response),
TwilioCreateMessageOutput(code=response['code']),
)
return self._output_stream.finalize()

def on_error(self, error: Any) -> None:
self._twilio_api_response = None
input = self._input.dict()

logger.error(f'Error in TwilioCreateMessageProcessor: {error}')
Expand All @@ -85,11 +91,18 @@ def on_error(self, error: Any) -> None:

response = self._send_message(
error_msg, to_=input['to'], from_=self._config.phone_number, account_sid=self._config.account_sid, auth_token=self._config.auth_token)

self._twilio_api_response = {
'code': response['code'],
'headers': response['headers'],
'text': response['text'],
}

async_to_sync(self._output_stream.write)(
TwilioCreateMessageOutput(response=response),
TwilioCreateMessageOutput(code=response['code']),
)
self._output_stream.finalize()
return super().on_error(error)

def get_bookkeeping_data(self) -> BookKeepingData:
return BookKeepingData(input=self._input, timestamp=time.time(), run_data={'twilio': {'requestor' : self._input.to}})
return BookKeepingData(input=self._input, timestamp=time.time(), run_data={'twilio': {'requestor' : self._input.to, 'messages_api_response': self._twilio_api_response}})
17 changes: 14 additions & 3 deletions llmstack/processors/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ def persist_history_task_internal(processors, bookkeeping_data_map):
'timestamp'] if 'agent' in bookkeeping_data_map else bookkeeping_data_map['output']['timestamp']
discord_data = bookkeeping_data_map['discord_processor'] if 'discord_processor' in bookkeeping_data_map else None
slack_data = bookkeeping_data_map['slack_processor'] if 'slack_processor' in bookkeeping_data_map else None
platform_data = discord_data['run_data'] if discord_data else (
slack_data['run_data'] if slack_data else {}
)
twilio_data = bookkeeping_data_map['twilio_processor'] if 'twilio_processor' in bookkeeping_data_map else None
platform_data = {}
if discord_data:
platform_data = discord_data['run_data']
elif slack_data:
platform_data = slack_data['run_data']
elif twilio_data:
platform_data = twilio_data['run_data']

processor_runs = []
for processor in processors:
Expand Down Expand Up @@ -64,6 +69,9 @@ def persist_history_task_internal(processors, bookkeeping_data_map):
elif discord_data:
response_body = discord_data['input']['text']
response_content_type = 'text/markdown'
elif twilio_data:
response_body = twilio_data['input']['body']
response_content_type = 'text/markdown'

response_time = output_timestamp - \
bookkeeping_data_map['input']['timestamp']
Expand All @@ -73,6 +81,9 @@ def persist_history_task_internal(processors, bookkeeping_data_map):
elif discord_data:
response_time = discord_data['timestamp'] - \
bookkeeping_data_map['input']['timestamp']
elif twilio_data:
response_time = twilio_data['timestamp'] - \
bookkeeping_data_map['input']['timestamp']

run_entry = RunEntry(
request_uuid=input['request_uuid'], app_uuid=input['request_app_uuid'] or None,
Expand Down