feat(adapter): send messages with dialogflow

This commit is contained in:
Juan Daniel
2022-12-23 22:40:35 +01:00
parent 4d8cf623ff
commit c20e151e20

View File

@@ -92,29 +92,22 @@ class DialogFlowCXContext extends CoreClass {
null, null,
] ]
const { queryResult } = single const listMessages = single.queryResult.responseMessages.map((res) => {
if (res.message == 'text') {
return { answer: res.text.text[0] }
}
const msgPayload = queryResult?.fulfillmentMessages?.find( if (res.message == 'payload') {
(a) => a.message === 'payload' const { values } = res.payload.fields.buttons.listValue
) const buttonsArray = values.map((values) => {
const { stringValue } = values.structValue.fields.body
if (msgPayload && msgPayload?.payload) { return { body: stringValue }
const { fields } = msgPayload.payload
const mapButtons = fields?.buttons?.listValue?.values.map((m) => {
return m?.structValue?.fields?.body?.stringValue
}) })
customPayload = { return { buttons: buttonsArray }
media: fields?.media?.stringValue,
buttons: mapButtons,
}
} }
})
const ctxFromDX = { this.sendFlow(listMessages, from)
...customPayload,
answer: queryResult?.fulfillmentText,
}
this.sendFlow([ctxFromDX], from)
} }
} }