2
0

🚸 (pictureChoice) Improve single picture choice with same titles

Closes #859
This commit is contained in:
Baptiste Arnaud
2023-09-28 15:35:21 +02:00
parent e10a506c96
commit d46e8013d4
5 changed files with 12 additions and 16 deletions

View File

@@ -68,22 +68,18 @@ export const parsePictureChoicesReply =
.join(', '),
}
}
if (state.whatsApp) {
const matchedItem = displayedItems.find((item) => item.id === inputValue)
if (!matchedItem) return { status: 'fail' }
return {
status: 'success',
reply: matchedItem.title ?? matchedItem.pictureSrc ?? '',
}
}
const longestItemsFirst = [...displayedItems].sort(
(a, b) => (b.title?.length ?? 0) - (a.title?.length ?? 0)
)
const matchedItem = longestItemsFirst.find(
(item) =>
item.title &&
item.id === inputValue ||
item.title
.toLowerCase()
?.toLowerCase()
.trim()
.includes(inputValue.toLowerCase().trim()) ||
item.pictureSrc
?.toLowerCase()
.trim()
.includes(inputValue.toLowerCase().trim())
)