fix: ensure messages are sent sequentially and update in light of chunking

Philipp Burckhardt 2023-06-15 12:02:25 -04:00
rodzic fd253b2ef0
commit 52bea40846
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: A2C3BCA4F31D1DDD
1 zmienionych plików z 14 dodań i 7 usunięć

Wyświetl plik

@ -249,9 +249,16 @@ export class TwilioConversationClient {
maxChunkLength?: number maxChunkLength?: number
}) { }) {
const chunks = chunkString(text, TWILIO_SMS_LENGTH_SOFT_LIMIT) const chunks = chunkString(text, TWILIO_SMS_LENGTH_SOFT_LIMIT)
return Promise.all( const out: TwilioConversationMessage[] = []
chunks.map((chunk) => this.sendMessage({ conversationSid, text: chunk })) for (const chunk of chunks) {
) const sent = await this.sendMessage({
conversationSid,
text: chunk
})
out.push(sent)
}
return out
} }
/** /**
@ -339,11 +346,11 @@ export class TwilioConversationClient {
} }
const response = await this.fetchMessages(conversationSid) const response = await this.fetchMessages(conversationSid)
const candidates = response.messages.filter(
(message) => message.author !== this.botName
)
if (response.messages.length > 1) { if (candidates.length > 0) {
const candidates = response.messages.filter(
(message) => message.author !== this.botName
)
const candidate = candidates[candidates.length - 1] const candidate = candidates[candidates.length - 1]
if (validate(candidate)) { if (validate(candidate)) {