chore: Add support for message_templates in API inbox (#4835)
This commit is contained in:
parent
9bac5873ef
commit
3f3ee6c34a
8 changed files with 44 additions and 25 deletions
|
@ -267,7 +267,8 @@ export default {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
hasWhatsappTemplates() {
|
hasWhatsappTemplates() {
|
||||||
return !!this.inbox.message_templates;
|
return !!this.$store.getters['inboxes/getWhatsAppTemplates'](this.inboxId)
|
||||||
|
.length;
|
||||||
},
|
},
|
||||||
enterToSendEnabled() {
|
enterToSendEnabled() {
|
||||||
return !!this.uiSettings.enter_to_send_enabled;
|
return !!this.uiSettings.enter_to_send_enabled;
|
||||||
|
|
|
@ -318,7 +318,6 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapGetters } from 'vuex';
|
import { mapGetters } from 'vuex';
|
||||||
import { required } from 'vuelidate/lib/validators';
|
|
||||||
import { shouldBeUrl } from 'shared/helpers/Validators';
|
import { shouldBeUrl } from 'shared/helpers/Validators';
|
||||||
import configMixin from 'shared/mixins/configMixin';
|
import configMixin from 'shared/mixins/configMixin';
|
||||||
import alertMixin from 'shared/mixins/alertMixin';
|
import alertMixin from 'shared/mixins/alertMixin';
|
||||||
|
@ -562,7 +561,6 @@ export default {
|
||||||
},
|
},
|
||||||
validations: {
|
validations: {
|
||||||
webhookUrl: {
|
webhookUrl: {
|
||||||
required,
|
|
||||||
shouldBeUrl,
|
shouldBeUrl,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -51,9 +51,20 @@ export const getters = {
|
||||||
const [inbox] = $state.records.filter(
|
const [inbox] = $state.records.filter(
|
||||||
record => record.id === Number(inboxId)
|
record => record.id === Number(inboxId)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const {
|
||||||
|
message_templates: whatsAppMessageTemplates,
|
||||||
|
additional_attributes: additionalAttributes,
|
||||||
|
} = inbox;
|
||||||
|
|
||||||
|
const { message_templates: apiInboxMessageTemplates } =
|
||||||
|
additionalAttributes || {};
|
||||||
|
const messagesTemplates =
|
||||||
|
whatsAppMessageTemplates || apiInboxMessageTemplates;
|
||||||
|
|
||||||
// filtering out the whatsapp templates with media
|
// filtering out the whatsapp templates with media
|
||||||
if (inbox.message_templates) {
|
if (messagesTemplates) {
|
||||||
return inbox.message_templates.filter(template => {
|
return messagesTemplates.filter(template => {
|
||||||
return !template.components.some(
|
return !template.components.some(
|
||||||
i => i.format === 'IMAGE' || i.format === 'VIDEO'
|
i => i.format === 'IMAGE' || i.format === 'VIDEO'
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
# Table name: channel_api
|
# Table name: channel_api
|
||||||
#
|
#
|
||||||
# id :bigint not null, primary key
|
# id :bigint not null, primary key
|
||||||
|
# additional_attributes :jsonb
|
||||||
# hmac_mandatory :boolean default(FALSE)
|
# hmac_mandatory :boolean default(FALSE)
|
||||||
# hmac_token :string
|
# hmac_token :string
|
||||||
# identifier :string
|
# identifier :string
|
||||||
|
@ -21,7 +22,7 @@ class Channel::Api < ApplicationRecord
|
||||||
include Channelable
|
include Channelable
|
||||||
|
|
||||||
self.table_name = 'channel_api'
|
self.table_name = 'channel_api'
|
||||||
EDITABLE_ATTRS = [:webhook_url].freeze
|
EDITABLE_ATTRS = [:webhook_url, { additional_attributes: {} }].freeze
|
||||||
|
|
||||||
has_secure_token :identifier
|
has_secure_token :identifier
|
||||||
has_secure_token :hmac_token
|
has_secure_token :hmac_token
|
||||||
|
|
|
@ -116,18 +116,19 @@ class Message < ApplicationRecord
|
||||||
|
|
||||||
def webhook_data
|
def webhook_data
|
||||||
{
|
{
|
||||||
id: id,
|
account: account.webhook_data,
|
||||||
content: content,
|
additional_attributes: additional_attributes,
|
||||||
created_at: created_at,
|
|
||||||
message_type: message_type,
|
|
||||||
content_type: content_type,
|
|
||||||
private: private,
|
|
||||||
content_attributes: content_attributes,
|
content_attributes: content_attributes,
|
||||||
source_id: source_id,
|
content_type: content_type,
|
||||||
sender: sender.try(:webhook_data),
|
content: content,
|
||||||
inbox: inbox.webhook_data,
|
|
||||||
conversation: conversation.webhook_data,
|
conversation: conversation.webhook_data,
|
||||||
account: account.webhook_data
|
created_at: created_at,
|
||||||
|
id: id,
|
||||||
|
inbox: inbox.webhook_data,
|
||||||
|
message_type: message_type,
|
||||||
|
private: private,
|
||||||
|
sender: sender.try(:webhook_data),
|
||||||
|
source_id: source_id
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,7 @@ end
|
||||||
if resource.api?
|
if resource.api?
|
||||||
json.webhook_url resource.channel.try(:webhook_url)
|
json.webhook_url resource.channel.try(:webhook_url)
|
||||||
json.inbox_identifier resource.channel.try(:identifier)
|
json.inbox_identifier resource.channel.try(:identifier)
|
||||||
|
json.additional_attributes resource.channel.try(:additional_attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
### WhatsApp Channel
|
### WhatsApp Channel
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddAdditionalAttributesToApiChannel < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_column :channel_api, :additional_attributes, :jsonb, default: {}
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2022_05_25_141844) do
|
ActiveRecord::Schema.define(version: 2022_06_10_091206) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pg_stat_statements"
|
enable_extension "pg_stat_statements"
|
||||||
|
@ -205,6 +205,7 @@ ActiveRecord::Schema.define(version: 2022_05_25_141844) do
|
||||||
t.string "identifier"
|
t.string "identifier"
|
||||||
t.string "hmac_token"
|
t.string "hmac_token"
|
||||||
t.boolean "hmac_mandatory", default: false
|
t.boolean "hmac_mandatory", default: false
|
||||||
|
t.jsonb "additional_attributes", default: {}
|
||||||
t.index ["hmac_token"], name: "index_channel_api_on_hmac_token", unique: true
|
t.index ["hmac_token"], name: "index_channel_api_on_hmac_token", unique: true
|
||||||
t.index ["identifier"], name: "index_channel_api_on_identifier", unique: true
|
t.index ["identifier"], name: "index_channel_api_on_identifier", unique: true
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue