iachat/db/migrate
Mazen Khalil ca5e112a8c
feat: TikTok channel (#12741)
fixes: #11834

This pull request introduces TikTok channel integration, enabling users
to connect and manage TikTok business accounts similarly to other
supported social channels. The changes span backend API endpoints,
authentication helpers, webhook handling, configuration, and frontend
components to support TikTok as a first-class channel.


**Key Notes**
* This integration is only compatible with TikTok Business Accounts
* Special permissions are required to access the TikTok [Business
Messaging
API](https://business-api.tiktok.com/portal/docs?id=1832183871604753).
* The Business Messaging API is region-restricted and is currently
unavailable to users in the EU.
* Only TEXT, IMAGE, and POST_SHARE messages are currently supported due
to limitations in the TikTok Business Messaging API
* A message will be successfully sent only if it contains text alone or
one image attachment. Messages with multiple attachments or those
combining text and attachments will fail and receive a descriptive error
status.
* Messages sent directly from the TikTok App will be synced into the
system
* Initiating a new conversation from the system is not permitted due to
limitations from the TikTok Business Messaging API.


**Backend: TikTok Channel Integration**

* Added `Api::V1::Accounts::Tiktok::AuthorizationsController` to handle
TikTok OAuth authorization initiation, returning the TikTok
authorization URL.
* Implemented `Tiktok::CallbacksController` to handle TikTok OAuth
callback, process authorization results, create or update channel/inbox,
and handle errors or denied scopes.
* Added `Webhooks::TiktokController` to receive and verify TikTok
webhook events, including signature verification and event dispatching.
* Created `Tiktok::IntegrationHelper` module for JWT-based token
generation and verification for secure TikTok OAuth state management.

**Configuration and Feature Flags**

* Added TikTok app credentials (`TIKTOK_APP_ID`, `TIKTOK_APP_SECRET`) to
allowed configs and app config, and registered TikTok as a feature in
the super admin features YAML.
[[1]](diffhunk://#diff-5e46e1d248631a1147521477d84a54f8ba6846ea21c61eca5f70042d960467f4R43)
[[2]](diffhunk://#diff-8bf37a019cab1dedea458c437bd93e34af1d6e22b1672b1d43ef6eaa4dcb7732R69)
[[3]](diffhunk://#diff-123164bea29f3c096b0d018702b090d5ae670760c729141bd4169a36f5f5c1caR74-R79)

**Frontend: TikTok Channel UI and Messaging Support**

* Added `TiktokChannel` API client for frontend TikTok authorization
requests.
* Updated channel icon mappings and tests to include TikTok
(`Channel::Tiktok`).
[[1]](diffhunk://#diff-b852739ed45def61218d581d0de1ba73f213f55570aa5eec52aaa08f380d0e16R16)
[[2]](diffhunk://#diff-3cd3ae32e94ef85f1f2c4435abf0775cc0614fb37ee25d97945cd51573ef199eR64-R69)
* Enabled TikTok as a supported channel in contact forms, channel
widgets, and feature toggles.
[[1]](diffhunk://#diff-ec59c85e1403aaed1a7de35971fe16b7033d5cd763be590903ebf8f1ca25a010R47)
[[2]](diffhunk://#diff-ec59c85e1403aaed1a7de35971fe16b7033d5cd763be590903ebf8f1ca25a010R69)
[[3]](diffhunk://#diff-725b90ca7e3a6837ec8291e9f57094f6a46b3ee00e598d16564f77f32cf354b0R26-R29)
[[4]](diffhunk://#diff-725b90ca7e3a6837ec8291e9f57094f6a46b3ee00e598d16564f77f32cf354b0R51-R54)
[[5]](diffhunk://#diff-725b90ca7e3a6837ec8291e9f57094f6a46b3ee00e598d16564f77f32cf354b0R68)
* Updated message meta logic to support TikTok-specific message statuses
(sent, delivered, read).
[[1]](diffhunk://#diff-e41239cf8dda36c1bd1066dbb17588ae8868e56289072c74b3a6d7ef5abdd696R23)
[[2]](diffhunk://#diff-e41239cf8dda36c1bd1066dbb17588ae8868e56289072c74b3a6d7ef5abdd696L63-R65)
[[3]](diffhunk://#diff-e41239cf8dda36c1bd1066dbb17588ae8868e56289072c74b3a6d7ef5abdd696L81-R84)
[[4]](diffhunk://#diff-e41239cf8dda36c1bd1066dbb17588ae8868e56289072c74b3a6d7ef5abdd696L103-R107)
* Added support for embedded message attachments (e.g., TikTok embeds)
with a new `EmbedBubble` component and updated message rendering logic.
[[1]](diffhunk://#diff-c3d701caf27d9c31e200c6143c11a11b9d8826f78aa2ce5aa107470e6fdb9d7fR31)
[[2]](diffhunk://#diff-047859f9368a46d6d20177df7d6d623768488ecc38a5b1e284f958fad49add68R1-R19)
[[3]](diffhunk://#diff-c3d701caf27d9c31e200c6143c11a11b9d8826f78aa2ce5aa107470e6fdb9d7fR316)
[[4]](diffhunk://#diff-cbc85e7c4c8d56f2a847d0b01cd48ef36e5f87b43023bff0520fdfc707283085R52)
* Adjusted reply policy and UI messaging for TikTok's 48-hour reply
window.
[[1]](diffhunk://#diff-0d691f6a983bd89502f91253ecf22e871314545d1e3d3b106fbfc76bf6d8e1c7R208-R210)
[[2]](diffhunk://#diff-0d691f6a983bd89502f91253ecf22e871314545d1e3d3b106fbfc76bf6d8e1c7R224-R226)

These changes collectively enable end-to-end TikTok channel support,
from configuration and OAuth flow to webhook processing and frontend
message handling.


------------

# TikTok App Setup & Configuration
1. Grant access to the Business Messaging API
([Documentation](https://business-api.tiktok.com/portal/docs?id=1832184145137922))
2. Set the app authorization redirect URL to
`https://FRONTEND_URL/tiktok/callback`
3. Update the installation config with TikTok App ID and Secret
4. Create a Business Messaging Webhook configuration and set the
callback url to `https://FRONTEND_URL/webhooks/tiktok`
([Documentation](https://business-api.tiktok.com/portal/docs?id=1832190670631937))
. You can do this by calling
`Tiktok::AuthClient.update_webhook_callback` from rails console once you
finish Tiktok channel configuration in super admin ( will be automated
in future )
5. Enable TikTok channel feature in an account

---------

Co-authored-by: Sojan Jose <sojan@pepalo.com>
Co-authored-by: iamsivin <iamsivin@gmail.com>
2025-12-17 07:54:50 -08:00
..
20230426130150_init_schema.rb chore: Squash migrations till 05/2023 (#8862) 2024-02-06 17:00:38 +04:00
20230503101201_create_sla_policies.rb feat: SLA CRUD APIs (EE) (#7027) 2023-05-11 22:42:56 +05:30
20230509101256_add_index_to_messages_created_at.rb feat(perf): add index to messages created at (#7044) 2023-05-10 11:34:49 +05:30
20230510060828_add_index_to_messages_for_reportings.rb feat: add index migration (#7050) 2023-05-10 17:55:14 +05:30
20230510113208_set_default_empty_string_for_contact_name.rb chore: Add migration to set the default empty string value for contact name (#7052) 2023-05-11 17:35:19 +05:30
20230515051424_update_article_image_keys.rb chore: Add custom RuboCop cop to enforce one class per file (#12947) 2025-11-26 12:53:04 +05:30
20230523104139_add_partial_index_for_resolved_contacts.rb feat(perf): contacts query performance (#7175) 2023-05-23 17:22:47 +05:30
20230525085402_add_custom_sender_name_toggle.rb feat: Ability to customise the email sender name [CW-1629] (#7345) 2023-07-04 20:46:01 +05:30
20230608040738_add_processed_message_content_to_messages.rb fix: Automations condition based quoted text (#7272) 2023-06-09 17:00:05 +05:30
20230612103936_add_index_to_reporting_events.rb feat: add index to reporting events [CW-1960] (#7294) 2023-06-12 18:23:42 +05:30
20230614044633_add_sender_name_to_in.rb feat: Ability to customise the email sender name [CW-1629] (#7345) 2023-07-04 20:46:01 +05:30
20230620132319_add_sla_policy_to_conversations.rb chore: Add sla policy association to conversation (#7360) 2023-06-21 14:48:50 +05:30
20230620212340_add_waiting_since_to_conversations.rb feat: Add a sort option for conversations waiting for a reply from an agent (#7364) 2023-06-21 13:20:39 -07:00
20230706090122_sentiment_column_to_messages.rb feat: Sentiment Analysis (#7475) 2023-07-12 15:03:31 +05:30
20230714054138_add_api_key_sid_to_twilio_sms.rb feat: Add support for API key authentication in Twilio (#7523) 2023-07-14 19:20:54 -07:00
20230727065605_add_partial_index_contact_account_id.rb feat(perf): contact page loading speed (#7629) 2023-07-27 13:32:22 +05:30
20230801180936_update_default_status_in_hooks.rb fix: Update the default status of the hooks to enabled (#7652) 2023-08-01 12:14:47 -07:00
20230905060223_add_regex_to_custom_attribute_definition.rb feat: Support Regex validation for custom attributes (#7856) 2024-01-23 18:01:57 +04:00
20231011041615_ensure_message_private_not_null.rb chore: Ensure null validation for private attribute in messages (#8085) 2023-10-11 13:16:59 +05:30
20231013072802_add_icon_to_categories.rb feat: Adds the ability to set an emoji for help center category (#8111) 2023-10-20 13:52:30 +05:30
20231114111614_change_feature_flags_to_bigint_in_accounts.rb feat: convert feature_flag to bigint [CW-2767] (#8350) 2023-11-17 15:50:24 -08:00
20231129091149_add_snoozed_until_to_notifications.rb feat: Snooze notification API (#8439) 2023-12-04 12:32:35 +05:30
20231201014644_remove_notifications_with_message_primary_actor.rb chore: Change primary actor to Conversation for all the notification types. (#8435) 2023-12-06 10:43:09 +05:30
20231211010807_add_cached_labels_list.rb chore(migration): Re-run database migration job for caching. (#8581) 2023-12-18 17:29:02 -08:00
20231219000743_re_run_cache_label_job.rb chore(migration): Re-run database migration job for caching. (#8581) 2023-12-18 17:29:02 -08:00
20231219073832_add_last_activity_at_to_notifications.rb feat: Add last_activity_at field to Notification model (#8585) 2023-12-20 13:02:37 +05:30
20231223033019_refactor_sla_policy_columns.rb feat: sla 1 - refactor sla_policies model and add applied_sla model (#8602) 2024-01-23 23:48:02 +05:30
20231223040257_create_applied_slas.rb feat: sla 1 - refactor sla_policies model and add applied_sla model (#8602) 2024-01-23 23:48:02 +05:30
20240124054340_add_contact_type_to_contacts.rb feat: Add contact_type attribute to contact model (#8768) 2024-01-24 12:26:47 +05:30
20240124084032_add_middle_name_and_last_name_to_contacts.rb feat: Add middle_name and last_name to contact model (#8771) 2024-01-24 16:22:04 +05:30
20240129080827_add_location_and_country_code_to_contacts.rb feat: Add attributes location and country_code to Contact model (#8803) 2024-01-29 14:10:14 +05:30
20240131040316_remove_imap_inbox_syned_at_from_channel_email.rb chore: Remove unused attribute imap_inbox_synced_at (#8822) 2024-01-31 11:48:46 +04:00
20240207103014_change_applied_sla_sla_status_to_enum.rb feat: Add sidekiq jobs to monitor applied SLAs (#8828) 2024-02-07 21:44:56 +04:00
20240213131252_add_blocked_to_contacts.rb feat: Ability to block contacts permanently (#8922) 2024-02-21 14:18:42 -08:00
20240215065844_add_meta_to_notifications.rb feat: Add meta to notification model (#8941) 2024-02-16 14:38:02 +05:30
20240216055809_add_unique_index_to_applied_slas.rb feat: sla-7 ensure applied_sla uniqueness (#8938) 2024-02-20 21:59:49 +05:30
20240306201954_change_identifier_type_in_notifications_subscriptions.rb fix: Change the column identifier from string to text to avoid overflow (#9073) 2024-03-07 11:13:01 +05:30
20240319062553_create_sla_events.rb feat: add sla events table (#9126) 2024-03-20 11:59:37 +05:30
20240322071629_convert_cached_label_list_to_text.rb fix: Convert cached_label_list to text (#9143) 2024-03-25 18:47:08 -07:00
20240415210313_add_channel_web_widget_to_portals.rb feat: Add widget to help center config (#9235) 2024-04-15 16:46:48 -07:00
20240515201632_index_improvements_conversations_contacts.rb chore: Improved indexes for Conversations & Contacts [CW-3300] (#9475) 2024-05-15 16:10:39 -07:00
20240516003531_add_index_for_message_type_account_date.rb chore: Add indexes to improve reporting performance (#9478) 2024-05-15 21:21:15 -07:00
20240726220747_add_custom_roles.rb feat: Add APIs to manage custom roles in Chatwoot (#9995) 2024-08-23 17:18:28 +05:30
20240923215335_add_locale_to_article.rb fix: Include uncategorized articles in the all article section to allow edit/delete (#10153) 2024-09-23 23:39:03 -07:00
20241217041352_fix_old_audio_alert_data.rb fix: Update old data to fix login issues (#10594) 2024-12-17 17:17:11 +05:30
20250104200055_create_captain_tables.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
20250104210328_remove_robin_tables.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
20250105001414_add_status_to_captain_documents.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
20250105005821_remove_not_null_from_captain_documents.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
20250107030743_add_config_to_captain_assistant.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
20250108031358_create_captain_inbox.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
20250108211541_remove_index_from_captain_assistants.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
20250116000103_add_status_to_captain_assistant_responses.rb feat: Add a review step for FAQs generated from conversations before using it (#10693) 2025-01-16 09:54:34 +05:30
20250116061033_convert_document_to_polymorphic_association.rb fix(ce): Check the edition before running the data migration (#10728) 2025-01-21 10:00:37 +05:30
20250207040150_add_meta_to_attachment.rb feat: Show shared contact's name in Telegram channel (#10856) 2025-02-11 19:39:54 +05:30
20250228185548_add_internal_attributes_to_accounts.rb feat: Add support for account abuse detection (#11001) 2025-02-28 15:28:19 -08:00
20250315202035_add_index_to_articles.rb chore: Limit the number of articles retrieved by widget (#11095) 2025-03-15 14:10:12 -07:00
20250326034635_add_instagram_channel.rb feat: Added Instagram channel migration (#11181) 2025-03-26 11:12:32 +05:30
20250402233933_remove_portal_members.rb chore: Clean up report & knowledge base policies (#11234) 2025-04-03 16:00:32 -07:00
20250410061725_convert_csml_bots_to_webhook_bots.rb feat: Implement UI for Agent Bots in settings and remove CSML support (#11276) 2025-04-16 18:02:49 +05:30
20250416182131_flip_chatwoot_v4_default_feature_flag_installation_config.rb chore: Enable chatwoot_v4 feature flag by default for accounts (#11321) 2025-04-17 08:53:37 +05:30
20250421082927_add_settings_column_to_account.rb feat: Add support for minutes in auto resolve feature (#11269) 2025-05-07 00:36:15 -07:00
20250421085134_update_auto_resolve_to_mminutes.rb feat: Add support for minutes in auto resolve feature (#11269) 2025-05-07 00:36:15 -07:00
20250512231036_create_copilot_threads.rb feat: Add support for persistent copilot threads and messages (#11489) 2025-05-15 17:37:04 -07:00
20250512231037_create_copilot_messages.rb feat: Add support for persistent copilot threads and messages (#11489) 2025-05-15 17:37:04 -07:00
20250514045638_add_csat_config_to_inboxes.rb feat: Improve CSAT responses (#11485) 2025-05-16 14:18:52 +05:30
20250523024825_remove_uuid_from_copilot_threads.rb feat: Add support for realtime-events in copilot-threads and copilot-messages (#11557) 2025-05-22 22:25:05 -07:00
20250523024826_remove_user_id_from_copilot_messages.rb feat: Add support for realtime-events in copilot-threads and copilot-messages (#11557) 2025-05-22 22:25:05 -07:00
20250523031839_change_message_type_to_integer_in_copilot_messages.rb feat: Add support for realtime-events in copilot-threads and copilot-messages (#11557) 2025-05-22 22:25:05 -07:00
20250620120000_create_channel_voice.rb feat: Whatsapp embedded signup (#11612) 2025-07-14 21:37:06 -07:00
20250627195529_add_index_to_messages.rb fix: disable_ddl_transaction! on add_index action (#11833) 2025-06-27 16:58:50 -07:00
20250709102213_add_template_params_to_campaigns.rb chore(annotations): sync model annotations with current schema (#12245) 2025-08-20 20:23:42 +02:00
20250710145708_create_captain_scenarios.rb feat: add Captain::Scenario Model and API [CW-4597] (#11907) 2025-07-14 16:12:38 +05:30
20250714104358_add_response_guidelines_and_guardrails_to_captain_assistants.rb feat: add response guidelines and guardrails field (#11911) 2025-07-15 08:56:03 +05:30
20250722083820_add_ssl_settings_to_portals.rb chore: Automate SSL with Cloudflare (#12021) 2025-07-24 13:09:06 +04:00
20250722152516_add_index_on_contact_type_and_account_id_to_contacts.rb feat: Introduce the crm_v2 feature flag for CRM changes (#12014) 2025-07-23 17:07:02 +04:00
20250805082345_add_metadata_to_captain_documents.rb feat: Add BE changes for captain pdf support for faq generation (#12113) 2025-08-27 20:31:22 +05:30
20250805160307_add_notifications_performance_index.rb perf: fix notifications duplicate query and add composite index (#12110) 2025-08-07 15:59:40 +05:30
20250806140000_create_assignment_policies.rb feat: Add migration files for assignment v2 (#12147) 2025-08-11 21:44:38 -07:00
20250806140001_create_inbox_assignment_policies.rb feat: Add migration files for assignment v2 (#12147) 2025-08-11 21:44:38 -07:00
20250806140002_create_agent_capacity_policies.rb feat: Add migration files for assignment v2 (#12147) 2025-08-11 21:44:38 -07:00
20250806140003_create_inbox_capacity_limits.rb feat: Add migration files for assignment v2 (#12147) 2025-08-11 21:44:38 -07:00
20250806140004_add_agent_capacity_policy_to_account_users.rb feat: Add migration files for assignment v2 (#12147) 2025-08-11 21:44:38 -07:00
20250806140005_create_leaves.rb feat: Add migration files for assignment v2 (#12147) 2025-08-11 21:44:38 -07:00
20250808123008_add_feature_citation_to_assistant_config.rb fix(migrations): skip AddFeatureCitationToAssistantConfig on OSS (#12244) 2025-08-20 19:15:19 +05:30
20250820130619_add_two_factor_to_users.rb feat: MFA (#12290) 2025-09-18 20:19:24 +05:30
20250822061042_add_content_templates_to_twilio_sms.rb feat: Added the backend support for twilio content templates (#12272) 2025-08-24 10:05:15 +05:30
20250825070005_create_account_saml_settings.rb feat: add saml model & controller [CW-2958] (#12289) 2025-09-03 13:30:42 -07:00
20250826000000_drop_telegram_bots.rb chore: remove unused telegram bot model (#12417) 2025-09-11 22:25:26 +05:30
20250916024703_add_allowed_domains_to_channel_widgets.rb feat: Introduce allowed_domains for web widget (#12450) 2025-09-17 10:01:27 +05:30
20250917012759_add_verified_to_channel_email.rb feat: Clean up email configuration for from and reply to emails (#12453) 2025-09-24 11:36:53 -07:00
20250929105219_create_companies.rb feat: Add company model and API with tests (#12548) 2025-10-08 07:53:43 -07:00
20250929132305_add_company_to_contacts.rb feat: Add company model and API with tests (#12548) 2025-10-08 07:53:43 -07:00
20251003091242_create_captain_custom_tools.rb feat(ee): Captain custom http tools (#12584) 2025-10-06 07:53:15 -07:00
20251010143218_add_name_to_webhooks.rb feat(webhooks): add name to webhook (#12641) 2025-11-13 13:28:15 +05:30
20251021082242_add_unique_index_to_companies_domain.rb feat: Add company backfill migration for existing contacts (Part 1) (#12657) 2025-11-03 20:03:47 +05:30
20251022152158_add_index_to_conversations_identifier.rb perf: Add database index on conversations identifier (#12715) 2025-10-28 15:12:46 +05:30
20251022162159_add_assignee_agent_bot_id_to_conversations.rb feat: APIs to assign agents_bots as assignee in conversations (#12836) 2025-11-18 18:20:58 -08:00
20251027091242_add_tiktok_channel.rb feat: TikTok channel (#12741) 2025-12-17 07:54:50 -08:00
20251111094402_add_contacts_count_to_companies.rb feat: Backend - Companies API endpoint with pagination and search (#12840) 2025-11-18 14:28:56 +05:30
20251114173609_change_source_id_to_text.rb fix: Change contact_inboxes.source_id to text column (#12882) 2025-11-17 16:09:36 +05:30
20251119161025_change_messages_source_id_to_text.rb fix: Change messages.source_id to text column (#12908) 2025-11-20 11:41:41 +05:30