Skip to content

Commit 2a3f06d

Browse files
authored
fix(ai-assistants-samples): move to new API structure (#564)
1 parent d67e404 commit 2a3f06d

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

ai-assistants-samples/assets/utils.private.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ async function sendMessageToAssistant(context, assistantSid, body) {
1313
: context.TWILIO_REGION?.startsWith('dev')
1414
? '.dev'
1515
: '';
16-
const url = `https://assistants${environmentPrefix}.twilio.com/v1/${assistantSid}/Messages`;
16+
const url = `https://assistants${environmentPrefix}.twilio.com/v1/Assistants/${assistantSid}/Messages`;
1717

18-
// Attention! There's explicitly no "await" since we want to do a "fire & forget"
1918
const response = await fetch(url, {
2019
method: 'POST',
2120
body: JSON.stringify(body),

ai-assistants-samples/functions/channels/conversations/flex-webchat.protected.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ exports.handler = async function (context, event, callback) {
6666
params.append('_assistantIdentity', AssistantIdentity);
6767
}
6868
const body = {
69-
Body,
70-
Identity: identity,
71-
SessionId: `conversations__${ChatServiceSid}/${ConversationSid}`,
69+
body: Body,
70+
identity,
71+
// eslint-disable-next-line camelcase
72+
session_id: `conversations__${ChatServiceSid}/${ConversationSid}`,
7273
// using a callback to handle AI Assistant responding
73-
Webhook: `https://${
74+
webhook: `https://${
7475
context.DOMAIN_NAME
7576
}/channels/conversations/response?${params.toString()}`,
7677
};

ai-assistants-samples/functions/channels/conversations/messageAdded.protected.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ exports.handler = async function (context, event, callback) {
5252
params.append('_assistantIdentity', AssistantIdentity);
5353
}
5454
const body = {
55-
Body: event.Body,
56-
Identity: identity,
57-
SessionId: `conversations__${ChatServiceSid}/${ConversationSid}`,
55+
body: event.Body,
56+
identity,
57+
// eslint-disable-next-line camelcase
58+
session_id: `conversations__${ChatServiceSid}/${ConversationSid}`,
5859
// using a callback to handle AI Assistant responding
59-
Webhook: `https://${
60+
webhook: `https://${
6061
context.DOMAIN_NAME
6162
}/channels/conversations/response?${params.toString()}`,
6263
};

ai-assistants-samples/functions/channels/messaging/incoming.protected.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ exports.handler = async function (context, event, callback) {
2020

2121
const token = await signRequest(context, event);
2222
const body = {
23-
Body: event.Body,
24-
Identity: event.From.startsWith('whatsapp:')
23+
body: event.Body,
24+
identity: event.From.startsWith('whatsapp:')
2525
? event.From
2626
: `phone:${event.From}`,
27-
SessionId: sessionId,
28-
Webhook: `https://${context.DOMAIN_NAME}/channels/messaging/response?_token=${token}`,
27+
// eslint-disable-next-line camelcase
28+
session_id: sessionId,
29+
webhook: `https://${context.DOMAIN_NAME}/channels/messaging/response?_token=${token}`,
2930
};
3031

3132
const response = new Twilio.Response();

0 commit comments

Comments
 (0)