decidim-chatbot 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.erb_lint.yml +2134 -0
- data/.github/workflows/website.yml +57 -0
- data/.gitignore +13 -0
- data/.gitlab-ci.yml +204 -0
- data/.node-version +1 -0
- data/.nvmrc +1 -0
- data/.rspec +2 -0
- data/.rubocop.yml +17 -0
- data/.ruby-version +1 -0
- data/.simplecov +36 -0
- data/CONTRIBUTING.md +54 -0
- data/Gemfile +50 -0
- data/Gemfile.lock +1013 -0
- data/LICENSE.md +661 -0
- data/README.md +62 -0
- data/Rakefile +54 -0
- data/app/commands/decidim/chatbot/admin/destroy_item.rb +25 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_exit.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_login.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_propose_proposals.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_read_blogs.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_read_proposals.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_vote_on_proposal.rb +12 -0
- data/app/commands/decidim/chatbot/admin/notifications/update_manual.rb +12 -0
- data/app/commands/decidim/chatbot/admin/notifications/update_phase.rb +12 -0
- data/app/commands/decidim/chatbot/admin/persist_item.rb +47 -0
- data/app/commands/decidim/chatbot/admin/reorder_items.rb +51 -0
- data/app/commands/decidim/chatbot/admin/send_test_notification.rb +74 -0
- data/app/commands/decidim/chatbot/admin/unsubscribe_user.rb +35 -0
- data/app/commands/decidim/chatbot/admin/update_chatbot.rb +17 -0
- data/app/commands/decidim/chatbot/notifications/deliver.rb +30 -0
- data/app/commands/decidim/chatbot/notifications/enqueue_phase.rb +67 -0
- data/app/commands/decidim/chatbot/notifications/send.rb +115 -0
- data/app/commands/decidim/chatbot/whatsapp/create_from_phone.rb +95 -0
- data/app/commands/decidim/chatbot/whatsapp/sync_phone.rb +56 -0
- data/app/controllers/decidim/api/rest_full/chatbot/base_controller.rb +52 -0
- data/app/controllers/decidim/api/rest_full/chatbot/chatbot_menu_items_controller.rb +49 -0
- data/app/controllers/decidim/api/rest_full/chatbot/chatbot_users_controller.rb +46 -0
- data/app/controllers/decidim/api/rest_full/chatbot/chatbots_controller.rb +40 -0
- data/app/controllers/decidim/chatbot/admin/chatbot_edit.rb +85 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/generals_controller.rb +43 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/menu_items_controller.rb +32 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/notifications_controller.rb +92 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/users/filterable.rb +33 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/users_controller.rb +53 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/whatsapps_controller.rb +59 -0
- data/app/controllers/decidim/chatbot/admin/chatbots_controller.rb +20 -0
- data/app/controllers/decidim/chatbot/admin/items_crud.rb +183 -0
- data/app/forms/decidim/chatbot/admin/chatbot_form.rb +20 -0
- data/app/forms/decidim/chatbot/admin/config_form.rb +20 -0
- data/app/forms/decidim/chatbot/admin/menu_item_form.rb +80 -0
- data/app/forms/decidim/chatbot/admin/menu_items/component_id_form.rb +60 -0
- data/app/forms/decidim/chatbot/admin/menu_items/exit_form.rb +24 -0
- data/app/forms/decidim/chatbot/admin/menu_items/login_form.rb +35 -0
- data/app/forms/decidim/chatbot/admin/menu_items/propose_proposals_form.rb +23 -0
- data/app/forms/decidim/chatbot/admin/menu_items/propose_proposals_labels.rb +53 -0
- data/app/forms/decidim/chatbot/admin/menu_items/read_blogs_form.rb +23 -0
- data/app/forms/decidim/chatbot/admin/menu_items/read_content_labels.rb +51 -0
- data/app/forms/decidim/chatbot/admin/menu_items/read_proposals_form.rb +23 -0
- data/app/forms/decidim/chatbot/admin/menu_items/vote_on_proposal_form.rb +123 -0
- data/app/forms/decidim/chatbot/admin/notification_item_form.rb +111 -0
- data/app/forms/decidim/chatbot/admin/notifications/manual_form.rb +13 -0
- data/app/forms/decidim/chatbot/admin/notifications/phase_form.rb +79 -0
- data/app/forms/decidim/chatbot/admin/notifications/template_fields.rb +60 -0
- data/app/forms/decidim/chatbot/admin/notifications/test_form.rb +179 -0
- data/app/helpers/decidim/chatbot/admin/items_helper.rb +44 -0
- data/app/jobs/decidim/chatbot/chatbot_webhook_job.rb +59 -0
- data/app/jobs/decidim/chatbot/send_notification_job.rb +33 -0
- data/app/models/decidim/chatbot/chatbot.rb +47 -0
- data/app/models/decidim/chatbot/item.rb +99 -0
- data/app/packs/.keep +0 -0
- data/app/presenters/decidim/chatbot/admin_log/chatbot_presenter.rb +42 -0
- data/app/presenters/decidim/chatbot/admin_log/item_presenter.rb +32 -0
- data/app/queries/decidim/chatbot/admin/proposal_vote_mode.rb +41 -0
- data/app/queries/decidim/chatbot/whatsapp_users.rb +58 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_menu_item_serializer.rb +113 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_notification_serializer.rb +19 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_serializer.rb +66 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_user_identity_serializer.rb +23 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_user_serializer.rb +28 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_webhook_serializer.rb +21 -0
- data/app/services/decidim/chatbot/chatbot_webhook_handler.rb +40 -0
- data/app/services/decidim/chatbot/notifications/bindings.rb +87 -0
- data/app/services/decidim/chatbot/whatsapp/body_parameters.rb +29 -0
- data/app/services/decidim/chatbot/whatsapp/graph_client.rb +136 -0
- data/app/services/decidim/chatbot/whatsapp/status_mapper.rb +93 -0
- data/app/services/decidim/chatbot/whatsapp/template_manager_url.rb +35 -0
- data/app/views/decidim/chatbot/admin/chatbots/generals/_menu_preview.html.erb +49 -0
- data/app/views/decidim/chatbot/admin/chatbots/generals/edit.html.erb +79 -0
- data/app/views/decidim/chatbot/admin/chatbots/index.html.erb +50 -0
- data/app/views/decidim/chatbot/admin/chatbots/menu_items/_form.html.erb +2 -0
- data/app/views/decidim/chatbot/admin/chatbots/menu_items/edit.html.erb +2 -0
- data/app/views/decidim/chatbot/admin/chatbots/menu_items/index.html.erb +43 -0
- data/app/views/decidim/chatbot/admin/chatbots/menu_items/new.html.erb +12 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/_form.html.erb +4 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/_manual_fields.html.erb +8 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/_phase_fields.html.erb +6 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/edit.html.erb +3 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/index.html.erb +40 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/new.html.erb +11 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/test.html.erb +35 -0
- data/app/views/decidim/chatbot/admin/chatbots/tabs/_whatsapp.html.erb +47 -0
- data/app/views/decidim/chatbot/admin/chatbots/users/_filters.html.erb +23 -0
- data/app/views/decidim/chatbot/admin/chatbots/users/index.html.erb +56 -0
- data/app/views/decidim/chatbot/admin/chatbots/whatsapps/show.html.erb +5 -0
- data/app/views/decidim/chatbot/admin/shared/_item_form.html.erb +64 -0
- data/app/views/decidim/chatbot/admin/shared/_row_actions.html.erb +28 -0
- data/app/views/decidim/chatbot/admin/shared/_tabs_menu.html.erb +13 -0
- data/app/views/decidim/chatbot/admin/shared/_type_fields.html.erb +2 -0
- data/app/views/decidim/chatbot/admin/shared/_type_picker.html.erb +15 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_component_id.html.erb +9 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_exit.html.erb +5 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_login.html.erb +8 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_manual.html.erb +16 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_phase.html.erb +46 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_propose_proposals.html.erb +10 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_read_blogs.html.erb +16 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_read_proposals.html.erb +16 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_vote_on_proposal.html.erb +26 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_abstention_label.html.erb +7 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_vote_label.html.erb +7 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_votes_closed_warning.html.erb +6 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_weight_labels.html.erb +15 -0
- data/bin/check +13 -0
- data/bin/ci-setup +38 -0
- data/bin/gen-node-client +112 -0
- data/bin/gen-openapi +248 -0
- data/bin/i18n-tasks +27 -0
- data/bin/postversion +17 -0
- data/config/i18n-tasks.yml +38 -0
- data/config/locales/decidim_chatbot.en.yml +323 -0
- data/config/locales/decidim_chatbot.fr.yml +29 -0
- data/contrib/decidim-node-client/.gitignore +4 -0
- data/contrib/decidim-node-client/.npmignore +1 -0
- data/contrib/decidim-node-client/.openapi-generator/FILES +8 -0
- data/contrib/decidim-node-client/.openapi-generator/VERSION +1 -0
- data/contrib/decidim-node-client/.openapi-generator-ignore +13 -0
- data/contrib/decidim-node-client/.yarnrc.yml +5 -0
- data/contrib/decidim-node-client/README.md +37 -0
- data/contrib/decidim-node-client/api.ts +14193 -0
- data/contrib/decidim-node-client/base.ts +70 -0
- data/contrib/decidim-node-client/common.ts +185 -0
- data/contrib/decidim-node-client/configuration.ts +138 -0
- data/contrib/decidim-node-client/git_push.sh +57 -0
- data/contrib/decidim-node-client/index.ts +16 -0
- data/contrib/decidim-node-client/package.json +49 -0
- data/contrib/decidim-node-client/packup.config.ts +7 -0
- data/contrib/decidim-node-client/tsconfig.json +25 -0
- data/contrib/decidim-node-client/yarn.lock +2367 -0
- data/crowdin.yml +15 -0
- data/db/migrate/20260725120000_create_decidim_chatbot_chatbots.rb +20 -0
- data/db/migrate/20260822120000_create_decidim_chatbot_items.rb +20 -0
- data/db/migrate/20260824120000_add_menu_and_error_copy_to_decidim_chatbot_chatbots.rb +13 -0
- data/db/migrate/20260824140000_add_enabled_to_decidim_chatbot_items.rb +7 -0
- data/decidim-chatbot.gemspec +40 -0
- data/docker-compose.ci.yml +59 -0
- data/docker-compose.yml +47 -0
- data/lib/decidim/chatbot/admin_engine.rb +67 -0
- data/lib/decidim/chatbot/admin_menu.rb +41 -0
- data/lib/decidim/chatbot/default_manifests.rb +91 -0
- data/lib/decidim/chatbot/engine.rb +107 -0
- data/lib/decidim/chatbot/manifest.rb +31 -0
- data/lib/decidim/chatbot/menu_item_label_keys.rb +26 -0
- data/lib/decidim/chatbot/registry.rb +42 -0
- data/lib/decidim/chatbot/rest_full_ability.rb +24 -0
- data/lib/decidim/chatbot/settings_tab.rb +18 -0
- data/lib/decidim/chatbot/test_definitions.rb +352 -0
- data/lib/decidim/chatbot/variable_interpolator.rb +30 -0
- data/lib/decidim/chatbot/version.rb +21 -0
- data/lib/decidim/chatbot/webhook_publisher.rb +29 -0
- data/lib/decidim/chatbot.rb +41 -0
- data/lib/decidim-chatbot.rb +3 -0
- data/lib/tasks/chatbot.rake +64 -0
- data/openapi/openapi.json +37801 -0
- data/openapitools.json +7 -0
- data/package.json +22 -0
- data/prettier.config.js +15 -0
- data/spec/commands/decidim/chatbot/admin/destroy_item_spec.rb +24 -0
- data/spec/commands/decidim/chatbot/admin/persist_item_spec.rb +80 -0
- data/spec/commands/decidim/chatbot/admin/reorder_items_spec.rb +53 -0
- data/spec/commands/decidim/chatbot/admin/send_test_notification_spec.rb +105 -0
- data/spec/commands/decidim/chatbot/admin/unsubscribe_user_spec.rb +46 -0
- data/spec/commands/decidim/chatbot/admin/update_chatbot_spec.rb +56 -0
- data/spec/commands/decidim/chatbot/notifications/enqueue_phase_spec.rb +59 -0
- data/spec/commands/decidim/chatbot/notifications/send_spec.rb +101 -0
- data/spec/commands/decidim/chatbot/whatsapp/create_from_phone_spec.rb +122 -0
- data/spec/commands/decidim/chatbot/whatsapp/sync_phone_spec.rb +110 -0
- data/spec/controllers/decidim/chatbot/admin/chatbots_controller_spec.rb +25 -0
- data/spec/factories/chatbot.rb +44 -0
- data/spec/forms/decidim/chatbot/admin/chatbot_form_spec.rb +41 -0
- data/spec/forms/decidim/chatbot/admin/config_form_spec.rb +30 -0
- data/spec/forms/decidim/chatbot/admin/menu_item_form_spec.rb +49 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/component_id_form_spec.rb +54 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/component_id_forms_spec.rb +512 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/exit_form_spec.rb +39 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/login_form_spec.rb +101 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/propose_proposals_form_prefill_spec.rb +26 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/read_blogs_form_prefill_spec.rb +22 -0
- data/spec/forms/decidim/chatbot/admin/notifications/manual_form_spec.rb +130 -0
- data/spec/forms/decidim/chatbot/admin/notifications/phase_form_spec.rb +79 -0
- data/spec/forms/decidim/chatbot/admin/notifications/test_form_spec.rb +172 -0
- data/spec/jobs/decidim/chatbot/chatbot_webhook_job_spec.rb +47 -0
- data/spec/jobs/decidim/chatbot/send_notification_job_spec.rb +53 -0
- data/spec/lib/decidim/chatbot/engine_spec.rb +44 -0
- data/spec/lib/decidim/chatbot/registry_spec.rb +30 -0
- data/spec/lib/decidim/chatbot/settings_tab_spec.rb +21 -0
- data/spec/lib/decidim/chatbot/variable_interpolator_spec.rb +34 -0
- data/spec/lib/decidim/chatbot/whatsapp/status_mapper_spec.rb +64 -0
- data/spec/lib/decidim/chatbot_spec.rb +59 -0
- data/spec/models/decidim/chatbot/chatbot_spec.rb +23 -0
- data/spec/models/decidim/chatbot/item_spec.rb +88 -0
- data/spec/presenters/decidim/chatbot/admin_log/chatbot_presenter_spec.rb +64 -0
- data/spec/queries/decidim/chatbot/admin/proposal_vote_mode_spec.rb +74 -0
- data/spec/queries/decidim/chatbot/whatsapp_users_spec.rb +57 -0
- data/spec/requests/decidim/api/rest_full/chatbot/chatbot_menu_items_controller_spec.rb +344 -0
- data/spec/requests/decidim/api/rest_full/chatbot/chatbot_users_controller_spec.rb +140 -0
- data/spec/requests/decidim/api/rest_full/chatbot/chatbots_controller_spec.rb +195 -0
- data/spec/requests/decidim/chatbot/admin/chatbots/notifications_controller_spec.rb +44 -0
- data/spec/requests/decidim/chatbot/admin/tenant_isolation_spec.rb +133 -0
- data/spec/requests/decidim/chatbot/admin/unsubscribe_user_spec.rb +28 -0
- data/spec/serializers/decidim/api/rest_full/chatbot/chatbot_menu_item_serializer_spec.rb +321 -0
- data/spec/serializers/decidim/api/rest_full/chatbot/chatbot_serializer_spec.rb +49 -0
- data/spec/serializers/decidim/api/rest_full/chatbot/chatbot_user_serializer_spec.rb +40 -0
- data/spec/services/decidim/chatbot/chatbot_webhook_handler_spec.rb +43 -0
- data/spec/services/decidim/chatbot/notifications/bindings_spec.rb +86 -0
- data/spec/services/decidim/chatbot/whatsapp/body_parameters_spec.rb +22 -0
- data/spec/services/decidim/chatbot/whatsapp/graph_client_spec.rb +205 -0
- data/spec/services/decidim/chatbot/whatsapp/template_manager_url_spec.rb +33 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/allow_all_hosts.rb +9 -0
- data/spec/support/chatbot_admin.rb +16 -0
- data/spec/support/decidim_factories.rb +7 -0
- data/spec/support/decidim_system_factories.rb +3 -0
- data/spec/support/devise.rb +5 -0
- data/spec/support/rack_test_system_driver.rb +43 -0
- data/spec/support/whatsapp_graph.rb +15 -0
- data/spec/swagger_helper.rb +47 -0
- data/spec/system/decidim/chatbot/admin/admin_can_send_manual_when_ready_spec.rb +35 -0
- data/spec/system/decidim/chatbot/admin/admin_configures_vote_on_proposal_menu_item_spec.rb +84 -0
- data/spec/system/decidim/chatbot/admin/admin_confirms_send_now_recipient_count_spec.rb +40 -0
- data/spec/system/decidim/chatbot/admin/admin_creates_menu_item_with_demo_field_spec.rb +65 -0
- data/spec/system/decidim/chatbot/admin/admin_creates_phase_and_manual_notifications_spec.rb +52 -0
- data/spec/system/decidim/chatbot/admin/admin_does_not_see_other_org_processes_in_phase_select_spec.rb +27 -0
- data/spec/system/decidim/chatbot/admin/admin_does_not_see_other_organization_chatbots_spec.rb +25 -0
- data/spec/system/decidim/chatbot/admin/admin_is_redirected_when_chatbot_is_disabled_spec.rb +28 -0
- data/spec/system/decidim/chatbot/admin/admin_lists_organization_chatbots_spec.rb +36 -0
- data/spec/system/decidim/chatbot/admin/admin_manual_notification_sends_with_nickname_spec.rb +68 -0
- data/spec/system/decidim/chatbot/admin/admin_navigates_chatbot_main_tabs_spec.rb +52 -0
- data/spec/system/decidim/chatbot/admin/admin_phase_notification_sends_on_step_change_spec.rb +79 -0
- data/spec/system/decidim/chatbot/admin/admin_picks_published_blog_component_spec.rb +205 -0
- data/spec/system/decidim/chatbot/admin/admin_picks_published_participatory_space_spec.rb +45 -0
- data/spec/system/decidim/chatbot/admin/admin_reorders_chatbot_menu_items_spec.rb +29 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_disabled_menu_item_faded_on_the_table_spec.rb +23 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_disabled_notification_item_faded_on_the_table_spec.rb +40 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_notification_facts_and_frozen_template_name_spec.rb +71 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_propose_proposals_defaults_prefilled_spec.rb +119 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_type_specific_fields_spec.rb +89 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_whatsapp_facts_and_can_sync_spec.rb +48 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_whatsapp_template_edit_link_spec.rb +37 -0
- data/spec/system/decidim/chatbot/admin/admin_tests_notification_spec.rb +125 -0
- data/spec/system/decidim/chatbot/admin/admin_unchecks_enabled_on_a_menu_item_spec.rb +30 -0
- data/spec/system/decidim/chatbot/admin/admin_unsubscribes_whatsapp_user_from_chatbot_spec.rb +35 -0
- data/spec/system/decidim/chatbot/admin/admin_updates_welcome_message_from_general_tab_spec.rb +84 -0
- data/spec/system/decidim/chatbot/system/admin_updates_organization_chatbot_settings_spec.rb +33 -0
- data/spec/tasks/chatbot_create_spec.rb +99 -0
- data/spec/tasks/chatbot_sync_spec.rb +90 -0
- data/website/.node-version +1 -0
- data/website/.nvmrc +1 -0
- data/website/docs/developer/_category_.json +4 -0
- data/website/docs/developer/contribute.md +87 -0
- data/website/docs/index.md +42 -0
- data/website/docs/integrate/_category_.json +4 -0
- data/website/docs/integrate/index.md +214 -0
- data/website/docusaurus.config.ts +93 -0
- data/website/package.json +37 -0
- data/website/sidebars.ts +7 -0
- data/website/src/css/custom.css +37 -0
- data/website/static/api-docs.html +2218 -0
- data/website/static/img/logo.svg +1 -0
- data/website/static/openapi.json +37801 -0
- data/website/tsconfig.json +6 -0
- data/website/yarn.lock +9782 -0
- data/yarn.lock +1003 -0
- metadata +424 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Notifications
|
|
6
|
+
# Interpolation bindings for a notification item and recipient.
|
|
7
|
+
class Bindings
|
|
8
|
+
def self.for(item, user)
|
|
9
|
+
new(item, user).to_h
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.format_date(date)
|
|
13
|
+
return "" if date.blank?
|
|
14
|
+
|
|
15
|
+
date.to_date.strftime("%d/%m/%Y")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def initialize(item, user)
|
|
19
|
+
@item = item
|
|
20
|
+
@user = user
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def to_h
|
|
24
|
+
shared.merge(phase_bindings)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
attr_reader :item, :user
|
|
30
|
+
|
|
31
|
+
def shared
|
|
32
|
+
{
|
|
33
|
+
"organization_name" => organization.name,
|
|
34
|
+
"chatbot_name" => translated(item.chatbot.name),
|
|
35
|
+
"user_name" => user.name,
|
|
36
|
+
"nickname" => user.nickname.to_s
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def phase_bindings
|
|
41
|
+
return {} unless space
|
|
42
|
+
|
|
43
|
+
{
|
|
44
|
+
"space_name" => translated(space.title),
|
|
45
|
+
"phase_name" => translated(step&.title),
|
|
46
|
+
"phase_start" => self.class.format_date(step&.start_date),
|
|
47
|
+
"phase_end" => self.class.format_date(step&.end_date)
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def space
|
|
52
|
+
@space ||= load_space
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def load_space
|
|
56
|
+
gid = item.settings["participatory_space_gid"].presence
|
|
57
|
+
return if gid.blank?
|
|
58
|
+
|
|
59
|
+
located = GlobalID::Locator.locate(gid)
|
|
60
|
+
located if same_org?(located)
|
|
61
|
+
rescue ActiveRecord::RecordNotFound
|
|
62
|
+
nil
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def same_org?(record)
|
|
66
|
+
record.respond_to?(:organization) && record.organization == organization
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def step
|
|
70
|
+
space&.steps&.find_by(active: true) if space.respond_to?(:steps)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def translated(value)
|
|
74
|
+
return "" if value.blank?
|
|
75
|
+
return value.to_s unless value.respond_to?(:[])
|
|
76
|
+
|
|
77
|
+
hash = value.to_h.stringify_keys
|
|
78
|
+
hash[I18n.locale.to_s].presence || hash.values.find(&:present?).to_s
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def organization
|
|
82
|
+
item.organization
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Whatsapp
|
|
6
|
+
# Maps stored variable hashes to Cloud API body parameters.
|
|
7
|
+
# Named templates ({{city}}) require parameter_name; positional {{1}} omit it.
|
|
8
|
+
class BodyParameters
|
|
9
|
+
def self.from(values)
|
|
10
|
+
values.to_h.stringify_keys.sort_by { |key, _| sort_key(key) }.map { |key, text| entry(key, text) }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.entry(key, text)
|
|
14
|
+
return { type: "text", text: text.to_s } if positional?(key)
|
|
15
|
+
|
|
16
|
+
{ type: "text", parameter_name: key.to_s, text: text.to_s }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.positional?(key)
|
|
20
|
+
key.to_s.match?(/\A\d+\z/)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.sort_key(key)
|
|
24
|
+
positional?(key) ? [0, key.to_i] : [1, key.to_s]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
module Decidim
|
|
7
|
+
module Chatbot
|
|
8
|
+
module Whatsapp
|
|
9
|
+
# Thin Graph API client for WhatsApp Cloud phone lookups.
|
|
10
|
+
# ponytail: ceiling — plaintext token from Toggle config; encrypt at rest when asked.
|
|
11
|
+
class GraphClient
|
|
12
|
+
BASE_URL = "https://graph.facebook.com"
|
|
13
|
+
|
|
14
|
+
def initialize(access_token:, business_id:)
|
|
15
|
+
@access_token = access_token
|
|
16
|
+
@business_id = business_id
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def fetch_phone(phone_id)
|
|
20
|
+
accounts.each do |account|
|
|
21
|
+
phones = phone_numbers(account["id"])
|
|
22
|
+
phone = phones.find { |row| row["id"].to_s == phone_id.to_s }
|
|
23
|
+
next unless phone
|
|
24
|
+
|
|
25
|
+
return phone_details(account["id"], phone)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def fetch_template(template_id)
|
|
32
|
+
get("#{template_id}?fields=name,language,status")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Resolves Meta template name + language from the template id. Decidim
|
|
36
|
+
# locales only choose which template_id to send; they are not Graph language codes.
|
|
37
|
+
def send_template(phone_id, to:, template_id:, parameters: [])
|
|
38
|
+
template = resolve_template(template_id)
|
|
39
|
+
post("#{phone_id}/messages", template_body(to, template[:name], template[:language], parameters))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
attr_reader :access_token, :business_id
|
|
45
|
+
|
|
46
|
+
def resolve_template(template_id)
|
|
47
|
+
data = fetch_template(template_id)
|
|
48
|
+
name = data["name"].to_s
|
|
49
|
+
language = data["language"].to_s
|
|
50
|
+
status = data["status"].to_s
|
|
51
|
+
raise "Graph API template missing name for id=#{template_id}" if name.blank?
|
|
52
|
+
raise "Graph API template missing language for id=#{template_id}" if language.blank?
|
|
53
|
+
raise "Graph API template #{name} (#{language}) is #{status.presence || "unknown"}; Meta only sends APPROVED templates" unless status.casecmp("APPROVED").zero?
|
|
54
|
+
|
|
55
|
+
{ name:, language:, status: }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def accounts
|
|
59
|
+
get("#{business_id}/owned_whatsapp_business_accounts?fields=id,name,created_time")["data"] || []
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def phone_numbers(waba_id)
|
|
63
|
+
get("#{waba_id}/phone_numbers")["data"] || []
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def subscribed_apps(waba_id)
|
|
67
|
+
data = get("#{waba_id}/subscribed_apps")["data"] || []
|
|
68
|
+
data.map { |app| (app["whatsapp_business_api_data"] || {}).with_indifferent_access }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def phone_details(waba_id, phone)
|
|
72
|
+
data = get("#{phone["id"]}?fields=health_status,platform_type,display_phone_number,verified_name")
|
|
73
|
+
{
|
|
74
|
+
id: phone["id"],
|
|
75
|
+
waba: waba_id,
|
|
76
|
+
subscribed_apps: subscribed_apps(waba_id),
|
|
77
|
+
health_status: data["health_status"],
|
|
78
|
+
platform_type: data["platform_type"],
|
|
79
|
+
display_phone_number: data["display_phone_number"] || phone["display_phone_number"],
|
|
80
|
+
verified_name: data["verified_name"]
|
|
81
|
+
}.with_indifferent_access
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def get(path)
|
|
85
|
+
perform(Net::HTTP::Get.new(graph_uri(path)))
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def post(path, payload)
|
|
89
|
+
perform(json_post(graph_uri(path), payload))
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def json_post(uri, payload)
|
|
93
|
+
req = Net::HTTP::Post.new(uri)
|
|
94
|
+
req["Content-Type"] = "application/json"
|
|
95
|
+
req.body = payload.to_json
|
|
96
|
+
req
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def perform(req)
|
|
100
|
+
req["Authorization"] = "Bearer #{access_token}"
|
|
101
|
+
parse(http_call(req))
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def http_call(req)
|
|
105
|
+
uri = req.uri
|
|
106
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def parse(res)
|
|
110
|
+
raise "Graph API #{res.code}: #{res.body}" unless res.is_a?(Net::HTTPSuccess)
|
|
111
|
+
|
|
112
|
+
JSON.parse(res.body)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def graph_uri(path)
|
|
116
|
+
URI("#{BASE_URL}/#{Decidim::Chatbot.whatsapp_api_version}/#{path}")
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def template_body(to, template_name, language, parameters)
|
|
120
|
+
{
|
|
121
|
+
messaging_product: "whatsapp",
|
|
122
|
+
to: to.to_s.gsub(/\D/, ""),
|
|
123
|
+
type: "template",
|
|
124
|
+
template: template_payload(template_name, language, parameters)
|
|
125
|
+
}
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def template_payload(template_name, language, parameters)
|
|
129
|
+
payload = { name: template_name, language: { code: language } }
|
|
130
|
+
payload[:components] = [{ type: "body", parameters: }] if parameters.present?
|
|
131
|
+
payload
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Whatsapp
|
|
6
|
+
# Maps Meta Graph phone health / subscription signals to chatbot statuses.
|
|
7
|
+
#
|
|
8
|
+
# Mapping (first match wins):
|
|
9
|
+
# - blocked — can_send_message == BLOCKED
|
|
10
|
+
# - waiting_2fa — health errors hint at PIN / 2FA registration
|
|
11
|
+
# - waiting_confirmation — health errors hint at pending verification
|
|
12
|
+
# - ready — CLOUD_API + subscribed + can_send AVAILABLE|LIMITED + no blocking errors
|
|
13
|
+
# - subscribed — WABA has at least one subscribed app, but not ready
|
|
14
|
+
# - created — phone exists in Meta, none of the above
|
|
15
|
+
class StatusMapper
|
|
16
|
+
# Meta Graph phone health_status error_code values (stringified).
|
|
17
|
+
# See https://developers.facebook.com/docs/whatsapp/cloud-api/health-status/
|
|
18
|
+
TWO_FA_ERROR_CODES = %w(
|
|
19
|
+
133005
|
|
20
|
+
133006
|
|
21
|
+
133008
|
|
22
|
+
).freeze # PIN / two-step verification not completed
|
|
23
|
+
CONFIRMATION_ERROR_CODES = %w(
|
|
24
|
+
133000
|
|
25
|
+
133010
|
|
26
|
+
133015
|
|
27
|
+
).freeze # registration / display-name confirmation pending
|
|
28
|
+
CALLING_NOISE_CODES = %w(
|
|
29
|
+
138024
|
|
30
|
+
138025
|
|
31
|
+
).freeze # calling-only noise; ignore for messaging readiness
|
|
32
|
+
|
|
33
|
+
def self.call(details)
|
|
34
|
+
new(details).call
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def initialize(details)
|
|
38
|
+
@details = details.with_indifferent_access
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def call
|
|
42
|
+
return "blocked" if can_send_message == "BLOCKED"
|
|
43
|
+
return "waiting_2fa" if matching_error?(TWO_FA_ERROR_CODES)
|
|
44
|
+
return "waiting_confirmation" if matching_error?(CONFIRMATION_ERROR_CODES)
|
|
45
|
+
return "ready" if ready?
|
|
46
|
+
return "subscribed" if subscribed?
|
|
47
|
+
|
|
48
|
+
"created"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
attr_reader :details
|
|
54
|
+
|
|
55
|
+
def ready?
|
|
56
|
+
details[:platform_type].to_s == "CLOUD_API" &&
|
|
57
|
+
subscribed? &&
|
|
58
|
+
%w(AVAILABLE LIMITED).include?(can_send_message) &&
|
|
59
|
+
phone_errors.empty?
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def subscribed?
|
|
63
|
+
Array(details[:subscribed_apps]).any?
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def can_send_message
|
|
67
|
+
phone_entity&.dig("can_send_message").presence ||
|
|
68
|
+
health_status["can_send_message"].to_s
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def matching_error?(codes)
|
|
72
|
+
phone_errors.any? { |error| codes.include?(error["error_code"].to_s) }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def phone_errors
|
|
76
|
+
@phone_errors ||= Array(phone_entity&.dig("errors")).reject do |error|
|
|
77
|
+
CALLING_NOISE_CODES.include?(error["error_code"].to_s)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def phone_entity
|
|
82
|
+
@phone_entity ||= Array(health_status["entities"]).find do |entity|
|
|
83
|
+
entity["entity_type"].to_s == "PHONE_NUMBER"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def health_status
|
|
88
|
+
@health_status ||= (details[:health_status] || {}).with_indifferent_access
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "cgi"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Chatbot
|
|
7
|
+
module Whatsapp
|
|
8
|
+
# Builds WhatsApp Manager URLs for editing message templates.
|
|
9
|
+
class TemplateManagerUrl
|
|
10
|
+
BASE = "https://business.facebook.com/latest/whatsapp_manager"
|
|
11
|
+
|
|
12
|
+
def self.for(organization, template_id)
|
|
13
|
+
return if template_id.blank?
|
|
14
|
+
|
|
15
|
+
business_id = business_id_for(organization)
|
|
16
|
+
return if business_id.blank?
|
|
17
|
+
|
|
18
|
+
"#{BASE}/#{CGI.escape(template_id.to_s)}/?reason=business_access&business_id=#{CGI.escape(business_id)}"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.message_templates_for(organization)
|
|
22
|
+
business_id = business_id_for(organization)
|
|
23
|
+
return if business_id.blank?
|
|
24
|
+
|
|
25
|
+
"#{BASE}/message_templates/?business_id=#{CGI.escape(business_id)}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.business_id_for(organization)
|
|
29
|
+
Decidim::Chatbot.credentials_for(organization)[:business_id].presence
|
|
30
|
+
end
|
|
31
|
+
private_class_method :business_id_for
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<%# locals: (chatbot:) %>
|
|
2
|
+
<div class="chatbot-whatsapp-preview">
|
|
3
|
+
<style>
|
|
4
|
+
.chatbot-whatsapp-preview { margin-block: 1rem; padding-inline: 1rem; }
|
|
5
|
+
.chatbot-whatsapp-preview__stage { max-width: 360px; }
|
|
6
|
+
.chatbot-whatsapp-preview__header { background: #005e54; color: #fff; padding: 0.75rem 1rem; font-weight: 600; }
|
|
7
|
+
.chatbot-whatsapp-preview__canvas { background: #efe7dd; min-height: 8rem; padding: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; }
|
|
8
|
+
.chatbot-whatsapp-preview__bubble { background: #fff; color: #111; border-radius: 0.5rem; padding: 0.5rem 0.75rem; max-width: 80%; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1); }
|
|
9
|
+
.chatbot-whatsapp-preview__card { background: #fff; color: #111; border-radius: 0.5rem; max-width: 80%; overflow: hidden; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1); }
|
|
10
|
+
.chatbot-whatsapp-preview__card-body { padding: 0.5rem 0.75rem; overflow-wrap: anywhere; }
|
|
11
|
+
.chatbot-whatsapp-preview__buttons { display: flex; flex-direction: column; }
|
|
12
|
+
.chatbot-whatsapp-preview__card-body + .chatbot-whatsapp-preview__buttons { border-top: 1px solid #e9edef; }
|
|
13
|
+
.chatbot-whatsapp-preview__button { padding: 0.625rem 0.75rem; text-align: center; color: #00a5f4; font-weight: 500; overflow-wrap: anywhere; }
|
|
14
|
+
.chatbot-whatsapp-preview__button + .chatbot-whatsapp-preview__button { border-top: 1px solid #e9edef; }
|
|
15
|
+
</style>
|
|
16
|
+
<div class="chatbot-whatsapp-preview__stage">
|
|
17
|
+
<div class="chatbot-whatsapp-preview__header"><%= translated_attribute(chatbot.name) %></div>
|
|
18
|
+
<div class="chatbot-whatsapp-preview__canvas">
|
|
19
|
+
<% welcome = translated_attribute(chatbot.welcome_message) %>
|
|
20
|
+
<% intro = translated_attribute(chatbot.menu_intro) %>
|
|
21
|
+
<% connector = translated_attribute(chatbot.menu_connector) %>
|
|
22
|
+
<% groups = chatbot.items.for_scope(:menu).enabled.to_a.each_slice(3).to_a %>
|
|
23
|
+
<% if welcome.present? %>
|
|
24
|
+
<div class="chatbot-whatsapp-preview__bubble"><%= welcome %></div>
|
|
25
|
+
<% end %>
|
|
26
|
+
<% if groups.empty? %>
|
|
27
|
+
<% if intro.present? %>
|
|
28
|
+
<div class="chatbot-whatsapp-preview__bubble"><%= intro %></div>
|
|
29
|
+
<% end %>
|
|
30
|
+
<% else %>
|
|
31
|
+
<% groups.each_with_index do |items, index| %>
|
|
32
|
+
<% body = index.zero? ? intro : connector %>
|
|
33
|
+
<div class="chatbot-whatsapp-preview__card">
|
|
34
|
+
<% if body.present? %>
|
|
35
|
+
<div class="chatbot-whatsapp-preview__card-body"><%= body %></div>
|
|
36
|
+
<% end %>
|
|
37
|
+
<div class="chatbot-whatsapp-preview__buttons">
|
|
38
|
+
<% items.each do |item| %>
|
|
39
|
+
<div class="chatbot-whatsapp-preview__button">
|
|
40
|
+
<span class="chatbot-whatsapp-preview__button-label"><%= translated_attribute(item.title) %></span>
|
|
41
|
+
</div>
|
|
42
|
+
<% end %>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
<% end %>
|
|
46
|
+
<% end %>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<%= render "decidim/chatbot/admin/shared/tabs_menu" %>
|
|
2
|
+
|
|
3
|
+
<div class="item__edit item__edit-1col">
|
|
4
|
+
<div class="item__edit-form">
|
|
5
|
+
<%= decidim_form_for(@form, url: chatbot_general_path(chatbot), method: :patch, html: { class: "form form-defaults" }) do |form| %>
|
|
6
|
+
<div class="form__wrapper">
|
|
7
|
+
<div class="card" data-controller="accordion" id="accordion-basic_settings">
|
|
8
|
+
<div class="card-divider">
|
|
9
|
+
<button class="card-divider-button" data-open="true" data-controls="panel-basic_settings" type="button">
|
|
10
|
+
<%= icon "arrow-right-s-line" %>
|
|
11
|
+
<h2 class="card-title" id="basic_settings">
|
|
12
|
+
<%= t("decidim.chatbot.admin.chatbots.general.basic_settings") %>
|
|
13
|
+
</h2>
|
|
14
|
+
</button>
|
|
15
|
+
</div>
|
|
16
|
+
<div id="panel-basic_settings" class="card-section">
|
|
17
|
+
<div class="row column">
|
|
18
|
+
<%= form.translated :text_area, :welcome_message,
|
|
19
|
+
rows: 6,
|
|
20
|
+
help_text: t("decidim.chatbot.admin.chatbots.general.welcome_message_help") %>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<div class="card" data-controller="accordion" id="accordion-menu">
|
|
26
|
+
<div class="card-divider">
|
|
27
|
+
<button class="card-divider-button" data-open="true" data-controls="panel-menu" type="button">
|
|
28
|
+
<%= icon "arrow-right-s-line" %>
|
|
29
|
+
<h2 class="card-title" id="menu">
|
|
30
|
+
<%= t("decidim.chatbot.admin.chatbots.general.menu") %>
|
|
31
|
+
</h2>
|
|
32
|
+
</button>
|
|
33
|
+
</div>
|
|
34
|
+
<div id="panel-menu" class="card-section">
|
|
35
|
+
<div class="row column">
|
|
36
|
+
<%= form.translated :text_field, :menu_intro,
|
|
37
|
+
help_text: t("decidim.chatbot.admin.chatbots.general.menu_intro_help") %>
|
|
38
|
+
</div>
|
|
39
|
+
<div class="row column">
|
|
40
|
+
<%= form.translated :text_field, :menu_connector,
|
|
41
|
+
help_text: t("decidim.chatbot.admin.chatbots.general.menu_connector_help") %>
|
|
42
|
+
</div>
|
|
43
|
+
<%= render "menu_preview", chatbot: %>
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<div class="card" data-controller="accordion" id="accordion-error_messages">
|
|
48
|
+
<div class="card-divider">
|
|
49
|
+
<button class="card-divider-button" data-open="true" data-controls="panel-error_messages" type="button">
|
|
50
|
+
<%= icon "arrow-right-s-line" %>
|
|
51
|
+
<h2 class="card-title" id="error_messages">
|
|
52
|
+
<%= t("decidim.chatbot.admin.chatbots.general.error_messages") %>
|
|
53
|
+
</h2>
|
|
54
|
+
</button>
|
|
55
|
+
</div>
|
|
56
|
+
<div id="panel-error_messages" class="card-section">
|
|
57
|
+
<div class="row column">
|
|
58
|
+
<%= form.translated :text_field, :error_404,
|
|
59
|
+
help_text: t("decidim.chatbot.admin.chatbots.general.error_404_help") %>
|
|
60
|
+
</div>
|
|
61
|
+
<div class="row column">
|
|
62
|
+
<%= form.translated :text_field, :error_502,
|
|
63
|
+
help_text: t("decidim.chatbot.admin.chatbots.general.error_502_help") %>
|
|
64
|
+
</div>
|
|
65
|
+
<div class="row column">
|
|
66
|
+
<%= form.translated :text_field, :error_401,
|
|
67
|
+
help_text: t("decidim.chatbot.admin.chatbots.general.error_401_help") %>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
<div class="item__edit-sticky">
|
|
73
|
+
<div class="item__edit-sticky-container">
|
|
74
|
+
<%= form.submit t("decidim.chatbot.admin.chatbots.edit.save"), class: "button button__sm button__secondary" %>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
<% end %>
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<% add_decidim_page_title(t("decidim.chatbot.admin.chatbots.index.title")) %>
|
|
2
|
+
|
|
3
|
+
<div class="card">
|
|
4
|
+
<div class="item_show__header">
|
|
5
|
+
<h1 class="item_show__header-title">
|
|
6
|
+
<%= t("decidim.chatbot.admin.chatbots.index.title") %>
|
|
7
|
+
</h1>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<% if chatbots.any? %>
|
|
11
|
+
<div class="table-stacked">
|
|
12
|
+
<table class="table-list">
|
|
13
|
+
<thead>
|
|
14
|
+
<tr>
|
|
15
|
+
<th><%= t("decidim.chatbot.admin.chatbots.index.headers.phone_number") %></th>
|
|
16
|
+
<th><%= t("decidim.chatbot.admin.chatbots.index.headers.display_name") %></th>
|
|
17
|
+
<th><%= t("decidim.chatbot.admin.chatbots.index.headers.status") %></th>
|
|
18
|
+
<th><%= t("decidim.chatbot.admin.chatbots.index.headers.name") %></th>
|
|
19
|
+
<th><%= t("decidim.chatbot.admin.chatbots.index.headers.actions") %></th>
|
|
20
|
+
</tr>
|
|
21
|
+
</thead>
|
|
22
|
+
<tbody>
|
|
23
|
+
<% chatbots.each do |row| %>
|
|
24
|
+
<tr>
|
|
25
|
+
<td data-label="<%= t("decidim.chatbot.admin.chatbots.index.headers.phone_number") %>">
|
|
26
|
+
<%= row.whatsapp_phone_number.presence || t("decidim.chatbot.admin.not_available") %>
|
|
27
|
+
</td>
|
|
28
|
+
<td data-label="<%= t("decidim.chatbot.admin.chatbots.index.headers.display_name") %>">
|
|
29
|
+
<%= row.whatsapp_display_name.presence || t("decidim.chatbot.admin.not_available") %>
|
|
30
|
+
</td>
|
|
31
|
+
<td data-label="<%= t("decidim.chatbot.admin.chatbots.index.headers.status") %>">
|
|
32
|
+
<%= t("decidim.chatbot.admin.chatbots.statuses.#{row.whatsapp_phone_status}") %>
|
|
33
|
+
</td>
|
|
34
|
+
<td data-label="<%= t("decidim.chatbot.admin.chatbots.index.headers.name") %>">
|
|
35
|
+
<%= translated_attribute(row.name) %>
|
|
36
|
+
</td>
|
|
37
|
+
<td data-label="<%= t("decidim.chatbot.admin.chatbots.index.headers.actions") %>" class="table-list__actions">
|
|
38
|
+
<%= link_to t("decidim.chatbot.admin.chatbots.index.edit"), edit_chatbot_general_path(row), class: "action-icon" %>
|
|
39
|
+
</td>
|
|
40
|
+
</tr>
|
|
41
|
+
<% end %>
|
|
42
|
+
</tbody>
|
|
43
|
+
</table>
|
|
44
|
+
</div>
|
|
45
|
+
<% else %>
|
|
46
|
+
<div class="card-section">
|
|
47
|
+
<%= cell("decidim/announcement", t("decidim.chatbot.admin.chatbots.index.empty_html"), callout_class: "secondary") %>
|
|
48
|
+
</div>
|
|
49
|
+
<% end %>
|
|
50
|
+
</div>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<%= render "decidim/chatbot/admin/shared/tabs_menu" %>
|
|
2
|
+
|
|
3
|
+
<div class="flex justify-end mb-4">
|
|
4
|
+
<%= link_to t("decidim.chatbot.admin.items.add"), new_chatbot_menu_item_path(chatbot), class: "button button__sm button__secondary" %>
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<% if @items.any? %>
|
|
8
|
+
<div class="table-stacked">
|
|
9
|
+
<table class="table-list">
|
|
10
|
+
<thead>
|
|
11
|
+
<tr>
|
|
12
|
+
<th></th>
|
|
13
|
+
<th><%= t("decidim.chatbot.admin.items.headers.title") %></th>
|
|
14
|
+
<th><%= t("decidim.chatbot.admin.items.headers.type") %></th>
|
|
15
|
+
<th><%= t("decidim.chatbot.admin.items.headers.actions") %></th>
|
|
16
|
+
</tr>
|
|
17
|
+
</thead>
|
|
18
|
+
<tbody class="draggable-table" data-sort-url="<%= reorder_chatbot_menu_items_path(chatbot) %>" data-draggable-table>
|
|
19
|
+
<% @items.each do |item| %>
|
|
20
|
+
<tr class="draggable-content" draggable="true" data-record-id="<%= item.id %>" style="<%= item_row_style(item) %>">
|
|
21
|
+
<td class="text-center dragging-handle" data-label="">
|
|
22
|
+
<%= icon("draggable", class: "dragger") %>
|
|
23
|
+
</td>
|
|
24
|
+
<td data-label="<%= t("decidim.chatbot.admin.items.headers.title") %>">
|
|
25
|
+
<%= translated_attribute(item.title) %>
|
|
26
|
+
</td>
|
|
27
|
+
<td data-label="<%= t("decidim.chatbot.admin.items.headers.type") %>">
|
|
28
|
+
<%= t("decidim.chatbot.admin.manifests.menu.#{item.manifest_name}") %>
|
|
29
|
+
</td>
|
|
30
|
+
<td class="table-list__actions" data-label="<%= t("decidim.chatbot.admin.items.headers.actions") %>">
|
|
31
|
+
<%= render "decidim/chatbot/admin/shared/row_actions",
|
|
32
|
+
record: item,
|
|
33
|
+
edit_path: edit_chatbot_menu_item_path(chatbot, item),
|
|
34
|
+
destroy_path: chatbot_menu_item_path(chatbot, item) %>
|
|
35
|
+
</td>
|
|
36
|
+
</tr>
|
|
37
|
+
<% end %>
|
|
38
|
+
</tbody>
|
|
39
|
+
</table>
|
|
40
|
+
</div>
|
|
41
|
+
<% else %>
|
|
42
|
+
<%= cell("decidim/announcement", t("decidim.chatbot.admin.items.menu_empty_html"), callout_class: "secondary") %>
|
|
43
|
+
<% end %>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<%= render "decidim/chatbot/admin/shared/tabs_menu" %>
|
|
2
|
+
|
|
3
|
+
<% if @form %>
|
|
4
|
+
<%= render "form",
|
|
5
|
+
url: chatbot_menu_items_path(chatbot),
|
|
6
|
+
form: @form,
|
|
7
|
+
heading: t("decidim.chatbot.admin.items.new_menu_item",
|
|
8
|
+
type: t("decidim.chatbot.admin.manifests.menu.#{@form.manifest_name}")),
|
|
9
|
+
cancel_path: chatbot_menu_items_path(chatbot) %>
|
|
10
|
+
<% else %>
|
|
11
|
+
<%= render "decidim/chatbot/admin/shared/type_picker", scope_name: :menu %>
|
|
12
|
+
<% end %>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<%# locals: (url:, form:, heading: nil) %>
|
|
2
|
+
<% send_now_path = form.persisted? && form.manifest_name == "manual" ? deliver_chatbot_notification_path(chatbot, item) : nil %>
|
|
3
|
+
<% send_now_confirm = send_now_path && t("decidim.chatbot.admin.items.send_now_confirm", count: subscribed_recipients_count) %>
|
|
4
|
+
<%= render "decidim/chatbot/admin/shared/item_form", form:, url:, heading:, send_now_path:, send_now_confirm: %>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<%# locals: (form:) %>
|
|
2
|
+
<% form.object.variable_keys.each do |key| %>
|
|
3
|
+
<div class="row column">
|
|
4
|
+
<label for="test_values_<%= key %>"><%= key %></label>
|
|
5
|
+
<%= text_field_tag "test[values][#{key}]", form.object.values[key],
|
|
6
|
+
id: "test_values_#{key}", autocomplete: "off" %>
|
|
7
|
+
</div>
|
|
8
|
+
<% end %>
|