Skip to content

Commit

Permalink
fix(ai-assistants-samples): move to new API structure (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkundel authored Sep 10, 2024
1 parent d67e404 commit 2a3f06d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
3 changes: 1 addition & 2 deletions ai-assistants-samples/assets/utils.private.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ async function sendMessageToAssistant(context, assistantSid, body) {
: context.TWILIO_REGION?.startsWith('dev')
? '.dev'
: '';
const url = `https://assistants${environmentPrefix}.twilio.com/v1/${assistantSid}/Messages`;
const url = `https://assistants${environmentPrefix}.twilio.com/v1/Assistants/${assistantSid}/Messages`;

// Attention! There's explicitly no "await" since we want to do a "fire & forget"
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify(body),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ exports.handler = async function (context, event, callback) {
params.append('_assistantIdentity', AssistantIdentity);
}
const body = {
Body,
Identity: identity,
SessionId: `conversations__${ChatServiceSid}/${ConversationSid}`,
body: Body,
identity,
// eslint-disable-next-line camelcase
session_id: `conversations__${ChatServiceSid}/${ConversationSid}`,
// using a callback to handle AI Assistant responding
Webhook: `https://${
webhook: `https://${
context.DOMAIN_NAME
}/channels/conversations/response?${params.toString()}`,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ exports.handler = async function (context, event, callback) {
params.append('_assistantIdentity', AssistantIdentity);
}
const body = {
Body: event.Body,
Identity: identity,
SessionId: `conversations__${ChatServiceSid}/${ConversationSid}`,
body: event.Body,
identity,
// eslint-disable-next-line camelcase
session_id: `conversations__${ChatServiceSid}/${ConversationSid}`,
// using a callback to handle AI Assistant responding
Webhook: `https://${
webhook: `https://${
context.DOMAIN_NAME
}/channels/conversations/response?${params.toString()}`,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ exports.handler = async function (context, event, callback) {

const token = await signRequest(context, event);
const body = {
Body: event.Body,
Identity: event.From.startsWith('whatsapp:')
body: event.Body,
identity: event.From.startsWith('whatsapp:')
? event.From
: `phone:${event.From}`,
SessionId: sessionId,
Webhook: `https://${context.DOMAIN_NAME}/channels/messaging/response?_token=${token}`,
// eslint-disable-next-line camelcase
session_id: sessionId,
webhook: `https://${context.DOMAIN_NAME}/channels/messaging/response?_token=${token}`,
};

const response = new Twilio.Response();
Expand Down

0 comments on commit 2a3f06d

Please sign in to comment.