Skip to content

Commit

Permalink
adding EVENTS.ORDER and EVENTS.TEMPLATE, as well as a button event, t…
Browse files Browse the repository at this point in the history
…o incoming messages in the Meta provider.
  • Loading branch information
ozzyoss77 committed Oct 9, 2023
1 parent 8b77c06 commit fa99d73
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/bot/core/core.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ class CoreClass extends EventEmitter {
if (LIST_REGEX.REGEX_EVENT_VOICE_NOTE.test(body)) {
msgToSend = this.flowClass.find(this.generalArgs.listEvents.VOICE_NOTE) || []
}

if (LIST_REGEX.REGEX_EVENT_ORDER.test(body)) {
msgToSend = this.flowClass.find(this.generalArgs.listEvents.ORDER) || []
}

if (LIST_REGEX.REGEX_EVENT_TEMPLATE.test(body)) {
msgToSend = this.flowClass.find(this.generalArgs.listEvents.TEMPLATE) || []
}
}
return exportFunctionsSend(() => sendFlow(msgToSend, from, { forceQueue: true }))
}
Expand Down
9 changes: 9 additions & 0 deletions packages/bot/io/events/eventOrder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { generateRef } = require('../../utils/hash')

const eventOrder = () => {
return generateRef('_event_order_')
}

const REGEX_EVENT_ORDER = /^_event_order__[\w\d]{8}-(?:[\w\d]{4}-){3}[\w\d]{12}$/

module.exports = { eventOrder, REGEX_EVENT_ORDER }
9 changes: 9 additions & 0 deletions packages/bot/io/events/eventTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { generateRef } = require('../../utils/hash')

const eventTemplate = () => {
return generateRef('_event_template_')
}

const REGEX_EVENT_TEMPLATE = /^_event_template__[\w\d]{8}-(?:[\w\d]{4}-){3}[\w\d]{12}$/

module.exports = { eventTemplate, REGEX_EVENT_TEMPLATE }
8 changes: 7 additions & 1 deletion packages/bot/io/events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const { eventDocument, REGEX_EVENT_DOCUMENT } = require('./eventDocument')
const { eventLocation, REGEX_EVENT_LOCATION } = require('./eventLocation')
const { eventMedia, REGEX_EVENT_MEDIA } = require('./eventMedia')
const { eventVoiceNote, REGEX_EVENT_VOICE_NOTE } = require('./eventVoiceNote')
const { eventOrder, REGEX_EVENT_ORDER } = require('./eventOrder')
const { eventTemplate, REGEX_EVENT_TEMPLATE } = require('./eventTemplate')
const { eventWelcome } = require('./eventWelcome')
const { eventAction } = require('./eventAction')

Expand All @@ -12,13 +14,17 @@ const LIST_ALL = {
DOCUMENT: eventDocument(),
VOICE_NOTE: eventVoiceNote(),
ACTION: eventAction(),
ORDER: eventOrder(),
TEMPLATE: eventTemplate()
}

const LIST_REGEX = {
REGEX_EVENT_DOCUMENT,
REGEX_EVENT_LOCATION,
REGEX_EVENT_MEDIA,
REGEX_EVENT_VOICE_NOTE,
REGEX_EVENT_ORDER,
REGEX_EVENT_TEMPLATE
}

module.exports = { LIST_ALL, LIST_REGEX }
module.exports = { LIST_ALL, LIST_REGEX }
31 changes: 31 additions & 0 deletions packages/provider/src/meta/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,37 @@ class MetaProvider extends ProviderClass {
return this.sendMessageMeta(body)
}

/**
* Enviar catálogo
* @param {*} number
* @param {*} bodyText
* @param {*} itemCatalogId
* @param {*} footerText
* @returns
*/

sendCatalog = async (number, bodyText, itemCatalogId) => {
const body = {
messaging_product: 'whatsapp',
recipient_type: 'individual',
to: number,
type: 'interactive',
interactive: {
type: 'catalog_message',
body: {
text: bodyText,
},
action: {
name: 'catalog_message',
parameters: {
"thumbnail_product_retailer_id": itemCatalogId,
}
}
}
}
return this.sendMessageMeta(body)
}

/**
*
* @param {*} userId
Expand Down
18 changes: 18 additions & 0 deletions packages/provider/src/meta/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,36 @@ class MetaWebHookServer extends EventEmitter {

if (message.type === 'interactive') {
const body = message.interactive?.button_reply?.title || message.interactive?.list_reply?.id
const title_button_reply = message.interactive?.button_reply?.title
const title_list_reply = message.interactive?.list_reply?.title
const responseObj = {
type: 'interactive',
from: message.from,
to,
body,
title_button_reply,
title_list_reply,
pushName,
}
this.emit('message', responseObj)
}

if (message.type === 'button') {
const body = message.button?.text
const payload = message.button?.payload
const title_button_reply = message.button?.payload
const responseObj = {
type: 'button',
from: message.from,
to,
body,
payload,
title_button_reply,
pushName,
}
this.emit('message', responseObj)
}

if (message.type === 'image') {
const body = generateRefprovider('_event_media_')
const idUrl = message.image?.id
Expand Down

0 comments on commit fa99d73

Please sign in to comment.