diff --git a/database/migrations/010_agenda_contatos.sql b/database/migrations/010_agenda_contatos.sql new file mode 100644 index 0000000..597985e --- /dev/null +++ b/database/migrations/010_agenda_contatos.sql @@ -0,0 +1,36 @@ +-- ============================================================ +-- Migration 010: Agenda geral de contatos +-- Tabela: agenda_contatos +-- ============================================================ + +CREATE TABLE IF NOT EXISTS agenda_contatos ( + chat_id VARCHAR(255) PRIMARY KEY, + phone VARCHAR(80) NOT NULL, + name VARCHAR(255), + company VARCHAR(255), + note TEXT, + updated_by_user_id INTEGER REFERENCES usuarios(id) ON DELETE SET NULL, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +DO $$ +BEGIN + IF to_regclass('public.customer_contacts') IS NOT NULL THEN + INSERT INTO agenda_contatos ( + chat_id, phone, name, company, note, updated_by_user_id, created_at, updated_at + ) + SELECT chat_id, phone, name, company, note, updated_by_user_id, created_at, updated_at + FROM customer_contacts + ON CONFLICT (chat_id) DO UPDATE SET + phone = EXCLUDED.phone, + name = EXCLUDED.name, + company = EXCLUDED.company, + note = EXCLUDED.note, + updated_by_user_id = EXCLUDED.updated_by_user_id, + updated_at = EXCLUDED.updated_at; + END IF; +END $$; + +CREATE INDEX IF NOT EXISTS idx_agenda_contatos_updated_at + ON agenda_contatos (updated_at DESC); diff --git a/database/migrations/011_whatsapp_opening_templates.sql b/database/migrations/011_whatsapp_opening_templates.sql new file mode 100644 index 0000000..7fc3bc6 --- /dev/null +++ b/database/migrations/011_whatsapp_opening_templates.sql @@ -0,0 +1,19 @@ +-- ============================================================ +-- Migration 011: Templates de abertura ativa do WhatsApp +-- Tabela: whatsapp_templates +-- ============================================================ + +INSERT INTO whatsapp_templates (name, content) VALUES +('abertura_atendimento_padrao', 'Ola, {nome}. Tudo bem? Estamos entrando em contato pelo atendimento. Podemos seguir por aqui?'), +('abertura_retorno_contato', 'Ola, {nome}. Estamos retornando seu contato para dar continuidade ao seu atendimento.'), +('abertura_suporte', 'Ola, {nome}. Aqui e do suporte. Estamos entrando em contato para te ajudar com sua solicitacao.'), +('abertura_financeiro', 'Ola, {nome}. Aqui e do financeiro. Estamos entrando em contato para tratar de uma informacao importante sobre seu atendimento.'), +('abertura_comercial', 'Ola, {nome}. Aqui e do comercial. Estamos entrando em contato para conversar sobre sua solicitacao.'), +('abertura_confirmacao_dados', 'Ola, {nome}. Precisamos confirmar alguns dados para seguir com seu atendimento.'), +('abertura_contato_agendado', 'Ola, {nome}. Este contato foi combinado anteriormente e estamos disponiveis para seguir.'), +('abertura_pos_atendimento', 'Ola, {nome}. Estamos fazendo um acompanhamento sobre seu atendimento recente.'), +('abertura_aviso_importante', 'Ola, {nome}. Temos uma informacao importante para compartilhar com voce.'), +('abertura_contato_inicial', 'Ola, {nome}. Vamos iniciar seu atendimento por este canal.') +ON CONFLICT (name) DO UPDATE SET + content = EXCLUDED.content, + updated_at = CURRENT_TIMESTAMP; diff --git a/database/migrations/012_whatsapp_awaiting_customer_reply.sql b/database/migrations/012_whatsapp_awaiting_customer_reply.sql new file mode 100644 index 0000000..3859212 --- /dev/null +++ b/database/migrations/012_whatsapp_awaiting_customer_reply.sql @@ -0,0 +1,10 @@ +-- ============================================================ +-- Migration 012: Bloqueio apos abertura ativa do WhatsApp +-- Tabela: whatsapp_chat_atribuicoes +-- ============================================================ + +ALTER TABLE whatsapp_chat_atribuicoes + ADD COLUMN IF NOT EXISTS awaiting_customer_reply BOOLEAN NOT NULL DEFAULT FALSE; + +CREATE INDEX IF NOT EXISTS idx_whatsapp_atribuicoes_awaiting_customer_reply + ON whatsapp_chat_atribuicoes (awaiting_customer_reply, status);