Skip to content

fix(ai-assistants-samples): move to new API structure #564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2024
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
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
Loading