diff --git a/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json b/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json index 9b5e183c33ce2..635dbd4a504ad 100644 --- a/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json +++ b/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json @@ -245,6 +245,66 @@ "PLACEHOLDER": "Check to ignore groups messages.", "ERROR": "Check to ignore groups messages." }, + "GENERATE_API_KEY": { + "LABEL": "Generate API Key", + "PLACEHOLDER": "Generate API Key", + "ERROR": "Generate API Key" + }, + "REJECT_CALLS": { + "LABEL": "Reject call", + "PLACEHOLDER": "Reject call.", + "ERROR": "Reject call." + }, + "MESSAGE_CALLS_WEBHOOK": { + "LABEL": "Message on reject call", + "PLACEHOLDER": "Message on reject call.", + "ERROR": "Message on reject call." + }, + "IGNORE_BROADCAST_STATUSES": { + "LABEL": "Ignore broadcast statuses", + "PLACEHOLDER": "Select to ignore broadcast statuses.", + "ERROR": "Select to ignore broadcast statuses." + }, + "IGNORE_BROADCAST_MESSAGES": { + "LABEL": "Ignore broadcast messages", + "PLACEHOLDER": "Select to ignore broadcast messages.", + "ERROR": "Select to ignore broadcast messages." + }, + "IGNORE_OWN_MESSAGES": { + "LABEL": "Ignore own messages", + "PLACEHOLDER": "Select to ignore own messages.", + "ERROR": "Select to ignore own messages." + }, + "IGNORE_YOURSELF_MESSAGES": { + "LABEL": "Ignore your messages", + "PLACEHOLDER": "Select to ignore your messages.", + "ERROR": "Select to ignore your messages." + }, + "SEND_CONNECTION_STATUS": { + "LABEL": "Show connection status", + "PLACEHOLDER": "Select to show connection status.", + "ERROR": "Select to show connection status." + }, + "NOTIFY_FAILED_MESSAGES": { + "LABEL": "Notify failed messages", + "PLACEHOLDER": "Select to notify failed messages.", + "ERROR": "Select to notify failed messages." + }, + "COMPOSING_MESSAGE": { + "LABEL": "Compose message", + "PLACEHOLDER": "Select to compose message.", + "ERROR": "Select to compose message." + }, + "SEND_REACTION_AS_REPLY": { + "LABEL": "Show reaction as reply", + "PLACEHOLDER": "Select to show reaction as reply.", + "ERROR": "Select to show reaction as reply." + }, + "SEND_PROFILE_PICTURE": { + "LABEL": "Show profile picture", + "PLACEHOLDER": "Select to show profile picture.", + "ERROR": "Select to show profile picture." + }, "URL": { "LABEL": "Unoapi URL", "PLACEHOLDER": "Please enter an Unoapi URL or use default https://unoapi.cloud", diff --git a/app/javascript/dashboard/i18n/locale/pt_BR/inboxMgmt.json b/app/javascript/dashboard/i18n/locale/pt_BR/inboxMgmt.json index db9136f534aa1..7624652ccfbe8 100644 --- a/app/javascript/dashboard/i18n/locale/pt_BR/inboxMgmt.json +++ b/app/javascript/dashboard/i18n/locale/pt_BR/inboxMgmt.json @@ -243,6 +243,71 @@ "PLACEHOLDER": "Por favor, digite um nome para caixa de entrada", "ERROR": "Este campo é obrigatório" }, + "GENERATE_API_KEY": { + "LABEL": "Generate API Key", + "PLACEHOLDER": "Generate API Key", + "ERROR": "Generate API Key" + }, + "REJECT_CALLS": { + "LABEL": "Rejeitar chamada", + "PLACEHOLDER": "Rejeitar chamada.", + "ERROR": "Rejeitar chamada." + }, + "MESSAGE_CALLS_WEBHOOK": { + "LABEL": "Mensagem ao rejeitar chamada", + "PLACEHOLDER": "Mensagem ao rejeitar chamada.", + "ERROR": "Mensagem ao rejeitar chamada." + }, + "IGNORE_BROADCAST_STATUSES": { + "LABEL": "Ignorar transmissão de status", + "PLACEHOLDER": "Selecione para ignorar transmissão de status.", + "ERROR": "Selecione para ignorar transmissão de status." + }, + "IGNORE_BROADCAST_MESSAGES": { + "LABEL": "Ignorar mensagens de transmissão", + "PLACEHOLDER": "Selecione para ignorar mensagens de transmissão.", + "ERROR": "Selecione para ignorar mensagens de transmissão." + }, + "IGNORE_OWN_MESSAGES": { + "LABEL": "Ignorar próprias mensagens", + "PLACEHOLDER": "Selecione para ignorar próprias mensagens.", + "ERROR": "Selecione para ignorar próprias mensagens." + }, + "IGNORE_YOURSELF_MESSAGES": { + "LABEL": "Ignorar suas mensagens", + "PLACEHOLDER": "Selecione para ignorar suas mensagens.", + "ERROR": "Selecione para ignorar suas mensagens." + }, + "SEND_CONNECTION_STATUS": { + "LABEL": "Exibir status de conexão", + "PLACEHOLDER": "Selecione para exibir status de conexão.", + "ERROR": "Selecione para exibir status de conexão." + }, + "NOTIFY_FAILED_MESSAGES": { + "LABEL": "Notificar mensagens com falha", + "PLACEHOLDER": "Selecione para notificar mensagens com falha.", + "ERROR": "Selecione para notificar mensagens com falha." + }, + "COMPOSING_MESSAGE": { + "LABEL": "Compor mensagem", + "PLACEHOLDER": "Selecione para compor mensagem.", + "ERROR": "Selecione para compor mensagem." + }, + "SEND_REACTION_AS_REPLY": { + "LABEL": "Mostrar reação como resposta", + "PLACEHOLDER": "Selecione para mostrar reação como resposta.", + "ERROR": "Selecione para mostrar reação como resposta." + }, + "SEND_PROFILE_PICTURE": { + "LABEL": "Exibir foto de perfil", + "PLACEHOLDER": "Selecione para exibir foto de perfil.", + "ERROR": "Selecione para exibir foto de perfil." + }, + "URL": { + "LABEL": "Unoapi URL", + "PLACEHOLDER": "Insira um URL Unoapi", + "ERROR": "Este campo é obrigatório" + }, "PHONE_NUMBER": { "LABEL": "Número de telefone", "PLACEHOLDER": "Por favor, insira o número de telefone do qual a mensagem será enviada.", diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/channels/Unoapi.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/channels/Unoapi.vue index 52ddd66c44be5..7d06ead53eab9 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/inbox/channels/Unoapi.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/channels/Unoapi.vue @@ -108,13 +108,32 @@ - + +
+ +
+
-
+ + @@ -136,6 +155,7 @@ export default { ignoreGroupMessages: true, ignoreHistoryMessages: true, sendAgentName: true, + webhookSendNewMessages: true, }; }, computed: { @@ -148,9 +168,25 @@ export default { ignoreGroupMessages: { required }, ignoreHistoryMessages: { required }, sendAgentName: { required }, + webhookSendNewMessages: { required }, url: { required }, }, methods: { + generateToken() { + const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + let token = ''; + for (let i = 0; i < 64; i++) { + token += characters.charAt(Math.floor(Math.random() * characters.length)); + } + + if (this.apiKey) { + if (confirm('A token already exists. Do you want to replace it?')) { + this.apiKey = token; + } + } else { + this.apiKey = token; + } + }, async createChannel() { this.$v.$touch(); if (this.$v.$invalid) { @@ -174,6 +210,7 @@ export default { ignore_history_messages: this.ignoreHistoryMessages, ignore_group_messages: this.ignoreGroupMessages, send_agent_name: this.sendAgentName, + webhook_send_new_messages: this.webhookSendNewMessages, url: this.url, }, }, diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/settingsPage/UnoapiConfiguration.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/settingsPage/UnoapiConfiguration.vue index ccbec9b5c56ad..14a586e5bfa9c 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/inbox/settingsPage/UnoapiConfiguration.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/settingsPage/UnoapiConfiguration.vue @@ -3,11 +3,14 @@
+
+ +
+ +
+ +
+
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
{{ notice }}
@@ -109,11 +290,16 @@ )} and ${$t('INBOX_MGMT.SETTINGS_POPUP.WHATSAPP_CONNECT')}`" @click="connect = true" /> - + +
@@ -143,10 +329,21 @@ export default { ignoreHistoryMessages: true, webhookSendNewMessages: true, sendAgentName: true, + ignoreBroadcastStatuses: true, + ignoreBroadcastMessages: true, + ignoreOwnMessages: true, + ignoreYourselfMessages: true, + sendConnectionStatus: true, + notifyFailedMessages: true, + composingMessage: true, + sendReactionAsReply: true, + sendProfilePicture: true, connect: false, disconect: false, qrcode: '', notice: '', + rejectCalls: '', + messageCallsWebhook: '', }; }, computed: { @@ -160,6 +357,17 @@ export default { webhookSendNewMessages: { required }, sendAgentName: { required }, url: { required }, + ignoreBroadcastStatuses: { required }, + ignoreBroadcastMessages: { required }, + ignoreOwnMessages: { required }, + ignoreYourselfMessages: { required }, + sendConnectionStatus: { required }, + notifyFailedMessages: { required }, + composingMessage: { required }, + sendReactionAsReply: { required }, + sendProfilePicture: { required }, + rejectCalls: { required }, + messageCallsWebhook: { required }, }, watch: { inbox() { @@ -174,13 +382,21 @@ export default { setDefaults() { this.apiKey = this.inbox.provider_config.api_key; this.url = this.inbox.provider_config.url; - this.ignoreGroupMessages = - this.inbox.provider_config.ignore_group_messages; - this.ignoreHistoryMessages = - this.inbox.provider_config.ignore_history_messages; - this.webhookSendNewMessages = - this.inbox.provider_config.webhook_send_new_messages; + this.ignoreGroupMessages = this.inbox.provider_config.ignore_group_messages; + this.ignoreHistoryMessages = this.inbox.provider_config.ignore_history_messages; + this.webhookSendNewMessages = this.inbox.provider_config.webhook_send_new_messages; this.sendAgentName = this.inbox.provider_config.send_agent_name; + this.ignoreBroadcastStatuses = this.inbox.provider_config.ignore_broadcast_statuses; + this.ignoreBroadcastMessages = this.inbox.provider_config.ignore_broadcast_messages; + this.ignoreOwnMessages = this.inbox.provider_config.ignore_own_messages; + this.ignoreYourselfMessages = this.inbox.provider_config.ignore_yourself_messages; + this.sendConnectionStatus = this.inbox.provider_config.send_connection_status; + this.notifyFailedMessages = this.inbox.provider_config.notify_failed_messages; + this.composingMessage = this.inbox.provider_config.composing_message; + this.sendReactionAsReply = this.inbox.provider_config.send_reaction_as_reply; + this.sendProfilePicture = this.inbox.provider_config.send_profile_picture; + this.rejectCalls = this.inbox.provider_config.reject_calls; + this.messageCallsWebhook = this.inbox.provider_config.message_calls_webhook; this.connect = false; this.disconect = false; }, @@ -223,6 +439,21 @@ export default { // } // ); }, + generateToken() { + const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + let token = ''; + for (let i = 0; i < 64; i++) { + token += characters.charAt(Math.floor(Math.random() * characters.length)); + } + + if (this.apiKey) { + if (confirm('A token already exists. Do you want to replace it?')) { + this.apiKey = token; + } + } else { + this.apiKey = token; + } + }, async updateInbox() { try { const payload = { @@ -237,6 +468,18 @@ export default { send_agent_name: this.sendAgentName, webhook_send_new_messages: this.webhookSendNewMessages, url: this.url, + webhook_send_new_messages: this.webhookSendNewMessages, + ignore_broadcast_statuses: this.ignoreBroadcastStatuses, + ignore_broadcast_messages: this.ignoreBroadcastMessages, + ignore_own_messages: this.ignoreOwnMessages, + ignore_yourself_messages: this.ignoreYourselfMessages, + send_connection_status: this.sendConnectionStatus, + notify_failed_messages: this.notifyFailedMessages, + composing_message: this.composingMessage, + send_reaction_as_reply: this.sendReactionAsReply, + send_profile_picture: this.sendProfilePicture, + reject_calls: this.rejectCalls, + message_calls_Webhook: this.messageCallsWebhook, connect: this.connect, disconect: this.disconect, }, diff --git a/app/services/whatsapp/unoapi_webhook_setup_service.rb b/app/services/whatsapp/unoapi_webhook_setup_service.rb index 08dd589f8f53c..7026624449655 100644 --- a/app/services/whatsapp/unoapi_webhook_setup_service.rb +++ b/app/services/whatsapp/unoapi_webhook_setup_service.rb @@ -24,6 +24,17 @@ def connect(whatsapp_channel) phone_number = whatsapp_channel.provider_config['business_account_id'] Rails.logger.debug { "Connecting #{phone_number} from unoapi" } body = { + ignoreGroupMessages: whatsapp_channel.provider_config['ignore_group_messages'], + ignoreBroadcastStatuses: whatsapp_channel.provider_config['ignore_broadcast_statuses'], + ignoreBroadcastMessages: whatsapp_channel.provider_config['ignore_broadcast_messages'], + ignoreHistoryMessages: whatsapp_channel.provider_config['ignore_history_messages'], + ignoreOwnMessages: whatsapp_channel.provider_config['ignore_own_messages'], + ignoreYourselfMessages: whatsapp_channel.provider_config['ignore_yourself_messages'], + sendConnectionStatus: whatsapp_channel.provider_config['send_connection_status'], + notifyFailedMessages: whatsapp_channel.provider_config['notify_failed_messages'], + composingMessage: whatsapp_channel.provider_config['composing_message'], + rejectCalls: whatsapp_channel.provider_config['reject_calls'], + messageCallsWebhook: whatsapp_channel.provider_config['message_calls_webhook'], webhooks: [ sendNewMessages: whatsapp_channel.provider_config['webhook_send_new_messages'], id: 'default', @@ -31,8 +42,8 @@ def connect(whatsapp_channel) token: whatsapp_channel.provider_config['webhook_verify_token'], header: :Authorization ], - ignoreGroupMessages: whatsapp_channel.provider_config['ignore_group_messages'], - ignoreHistoryMessages: whatsapp_channel.provider_config['ignore_history_messages'], + sendReactionAsReply: whatsapp_channel.provider_config['send_reaction_as_reply'], + sendProfilePicture: whatsapp_channel.provider_config['send_profile_picture'], authToken: whatsapp_channel.provider_config['api_key'] } response = HTTParty.post("#{url(whatsapp_channel)}/register", headers: headers(whatsapp_channel), body: body.to_json)