mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-20 20:49:15 +00:00
feat(adapter): ⚡ send messages with dialogflow
This commit is contained in:
@@ -92,29 +92,22 @@ class DialogFlowCXContext extends CoreClass {
|
|||||||
null,
|
null,
|
||||||
]
|
]
|
||||||
|
|
||||||
const { queryResult } = single
|
const listMessages = single.queryResult.responseMessages.map((res) => {
|
||||||
|
if (res.message == 'text') {
|
||||||
const msgPayload = queryResult?.fulfillmentMessages?.find(
|
return { answer: res.text.text[0] }
|
||||||
(a) => a.message === 'payload'
|
|
||||||
)
|
|
||||||
|
|
||||||
if (msgPayload && msgPayload?.payload) {
|
|
||||||
const { fields } = msgPayload.payload
|
|
||||||
const mapButtons = fields?.buttons?.listValue?.values.map((m) => {
|
|
||||||
return m?.structValue?.fields?.body?.stringValue
|
|
||||||
})
|
|
||||||
customPayload = {
|
|
||||||
media: fields?.media?.stringValue,
|
|
||||||
buttons: mapButtons,
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const ctxFromDX = {
|
if (res.message == 'payload') {
|
||||||
...customPayload,
|
const { values } = res.payload.fields.buttons.listValue
|
||||||
answer: queryResult?.fulfillmentText,
|
const buttonsArray = values.map((values) => {
|
||||||
}
|
const { stringValue } = values.structValue.fields.body
|
||||||
|
return { body: stringValue }
|
||||||
|
})
|
||||||
|
return { buttons: buttonsArray }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
this.sendFlow([ctxFromDX], from)
|
this.sendFlow(listMessages, from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user