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,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
module Chatbots
|
|
7
|
+
class WhatsappsController < Decidim::Admin::ApplicationController
|
|
8
|
+
include Decidim::Chatbot::Admin::ChatbotEdit
|
|
9
|
+
|
|
10
|
+
def show
|
|
11
|
+
authorize_org!
|
|
12
|
+
chatbot
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def sync
|
|
16
|
+
authorize_org!
|
|
17
|
+
run_sync
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def link
|
|
21
|
+
authorize_org!
|
|
22
|
+
run_link
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def run_sync
|
|
28
|
+
Whatsapp::SyncPhone.call(chatbot) do
|
|
29
|
+
on(:ok) { redirect_whatsapp(:success) }
|
|
30
|
+
on(:invalid) { redirect_whatsapp(:error) }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def run_link
|
|
35
|
+
Whatsapp::CreateFromPhone.call(organization: current_organization, phone_id: link_phone_id) do
|
|
36
|
+
on(:ok) { |created| redirect_linked(created) }
|
|
37
|
+
on(:invalid) { redirect_whatsapp(:error) }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def link_phone_id
|
|
42
|
+
params[:phone_id].presence || chatbot.whatsapp_phone_id
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def redirect_linked(created)
|
|
46
|
+
flash[:notice] = I18n.t("chatbots.whatsapp.success", scope: "decidim.chatbot.admin")
|
|
47
|
+
redirect_to chatbot_whatsapp_path(created)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def redirect_whatsapp(kind)
|
|
51
|
+
key = kind == :success ? :notice : :alert
|
|
52
|
+
flash[key] = I18n.t("chatbots.whatsapp.#{kind}", scope: "decidim.chatbot.admin")
|
|
53
|
+
redirect_to chatbot_whatsapp_path(chatbot)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
class ChatbotsController < Decidim::Admin::ApplicationController
|
|
7
|
+
include Decidim::Chatbot::Admin::ChatbotEdit
|
|
8
|
+
|
|
9
|
+
def index
|
|
10
|
+
authorize_org!
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def edit
|
|
14
|
+
authorize_org!
|
|
15
|
+
redirect_to edit_chatbot_general_path(chatbot)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
# Shared Menu / Notification item CRUD. Implement `#item_scope`.
|
|
7
|
+
module ItemsCrud
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
included do
|
|
11
|
+
helper_method :item, :type_picker_path
|
|
12
|
+
before_action :append_new_item_breadcrumb, only: [:new, :create]
|
|
13
|
+
before_action :append_edit_item_breadcrumb, only: [:edit, :update]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def index
|
|
17
|
+
authorize_org!
|
|
18
|
+
@items = collection
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def new
|
|
22
|
+
authorize_org!
|
|
23
|
+
assign_new_form
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def create
|
|
27
|
+
authorize_org!
|
|
28
|
+
persist_new_item
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def edit
|
|
32
|
+
authorize_org!
|
|
33
|
+
assign_edit_form
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def update
|
|
37
|
+
authorize_org!
|
|
38
|
+
persist_existing_item
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def destroy
|
|
42
|
+
authorize_org!
|
|
43
|
+
destroy_current_item
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def collection
|
|
49
|
+
chatbot.items.for_scope(item_scope)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def item
|
|
53
|
+
@item ||= collection.find(params[:id])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def assign_new_form
|
|
57
|
+
return unless params[:manifest_name]
|
|
58
|
+
|
|
59
|
+
@form = build_new_form
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def build_new_form
|
|
63
|
+
return form(resolved_form_class).from_params(params) if params[:item].present?
|
|
64
|
+
|
|
65
|
+
built = form(resolved_form_class).instance
|
|
66
|
+
built.manifest_name = params[:manifest_name]
|
|
67
|
+
built.prefill_defaults!
|
|
68
|
+
built
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def assign_edit_form
|
|
72
|
+
return overlay_edit_form if params[:item].present?
|
|
73
|
+
|
|
74
|
+
@form = form(item.manifest.form_class).from_model(item)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def overlay_edit_form
|
|
78
|
+
@form = form(item.manifest.form_class).from_params(params)
|
|
79
|
+
@form.id = item.id
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def persist_new_item
|
|
83
|
+
@form = form(resolved_form_class).from_params(params)
|
|
84
|
+
run_persist(build_item, :new)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def persist_existing_item
|
|
88
|
+
@form = form(item.manifest.form_class).from_params(params, item:)
|
|
89
|
+
run_persist(item, :edit)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def run_persist(record, template)
|
|
93
|
+
command_for(record).call(@form, record) do
|
|
94
|
+
on(:ok) { redirect_after_save(record, created: template == :new) }
|
|
95
|
+
on(:invalid) { render template, status: :unprocessable_content }
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def destroy_current_item
|
|
100
|
+
DestroyItem.call(item) do
|
|
101
|
+
on(:ok) { redirect_after_save(item, created: false) }
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def redirect_after_save(record, created:)
|
|
106
|
+
flash[:notice] = I18n.t("items.update.success", scope: "decidim.chatbot.admin")
|
|
107
|
+
redirect_to(created ? edit_item_path(record) : after_save_path)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def edit_item_path(record)
|
|
111
|
+
return edit_chatbot_menu_item_path(chatbot, record) if item_scope == :menu
|
|
112
|
+
|
|
113
|
+
edit_chatbot_notification_path(chatbot, record)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def after_save_path
|
|
117
|
+
return chatbot_menu_items_path(chatbot) if item_scope == :menu
|
|
118
|
+
|
|
119
|
+
chatbot_notifications_path(chatbot)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def build_item
|
|
123
|
+
chatbot.items.new(scope: item_scope.to_s, manifest_name: @form.manifest_name,
|
|
124
|
+
position: next_position)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def next_position
|
|
128
|
+
collection.maximum(:position).to_i + 1
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def resolved_form_class
|
|
132
|
+
found_manifest.form_class
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def found_manifest
|
|
136
|
+
name = params[:manifest_name].presence || params.dig(:item, :manifest_name)
|
|
137
|
+
found = Decidim::Chatbot.registry.for(item_scope).find { |entry| entry.name.to_s == name.to_s }
|
|
138
|
+
found || raise(ActiveRecord::RecordNotFound)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def command_for(record)
|
|
142
|
+
(record.manifest || found_manifest).command_class
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def type_picker_path(scope_name, manifest_name)
|
|
146
|
+
return new_chatbot_menu_item_path(chatbot, manifest_name:) if scope_name.to_s == "menu"
|
|
147
|
+
|
|
148
|
+
new_chatbot_notification_path(chatbot, manifest_name:)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def append_new_item_breadcrumb
|
|
152
|
+
controller_breadcrumb_items << { label: new_item_breadcrumb_label, url: "" }
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def new_item_breadcrumb_label
|
|
156
|
+
return I18n.t("items.new_menu_breadcrumb", scope: "decidim.chatbot.admin") if item_scope == :menu
|
|
157
|
+
|
|
158
|
+
I18n.t("items.new_notification_breadcrumb", scope: "decidim.chatbot.admin")
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def append_edit_item_breadcrumb
|
|
162
|
+
controller_breadcrumb_items << { label: edit_item_breadcrumb_label, url: "" }
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def edit_item_breadcrumb_label
|
|
166
|
+
return I18n.t("items.edit_menu_breadcrumb", scope: "decidim.chatbot.admin", title: edit_breadcrumb_name) if item_scope == :menu
|
|
167
|
+
|
|
168
|
+
I18n.t("items.edit_notification_breadcrumb", scope: "decidim.chatbot.admin", template_id: edit_breadcrumb_name)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def edit_breadcrumb_name
|
|
172
|
+
name = item_scope == :menu ? locale_value(item.title) : item.template_id_for(I18n.locale)
|
|
173
|
+
name.presence || I18n.t("not_available", scope: "decidim.chatbot.admin")
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def locale_value(value)
|
|
177
|
+
hash = value.to_h.stringify_keys
|
|
178
|
+
hash[I18n.locale.to_s].presence || hash.values.find(&:present?).to_s
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
class ChatbotForm < Decidim::Form
|
|
7
|
+
include Decidim::TranslatableAttributes
|
|
8
|
+
|
|
9
|
+
mimic :chatbot
|
|
10
|
+
|
|
11
|
+
translatable_attribute :welcome_message, String
|
|
12
|
+
translatable_attribute :menu_intro, String
|
|
13
|
+
translatable_attribute :menu_connector, String
|
|
14
|
+
translatable_attribute :error_404, String
|
|
15
|
+
translatable_attribute :error_502, String
|
|
16
|
+
translatable_attribute :error_401, String
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
class ConfigForm < Decidim::Form
|
|
7
|
+
include Decidim::Toggle::TabForm
|
|
8
|
+
include Decidim::Toggle::ModuleConfigForm
|
|
9
|
+
|
|
10
|
+
self.module_config_name = Decidim::Chatbot::MODULE_NAME
|
|
11
|
+
|
|
12
|
+
mimic :organization
|
|
13
|
+
|
|
14
|
+
attribute :enabled, :boolean, default: false
|
|
15
|
+
attribute :access_token, :string
|
|
16
|
+
attribute :business_id, :string
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
class MenuItemForm < Decidim::Form
|
|
7
|
+
include Decidim::TranslatableAttributes
|
|
8
|
+
|
|
9
|
+
mimic :item
|
|
10
|
+
|
|
11
|
+
def self.inherited(subclass)
|
|
12
|
+
super
|
|
13
|
+
subclass.mimic :item
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
TITLE_MAX_LENGTH = 20
|
|
17
|
+
|
|
18
|
+
translatable_attribute :title, String do |name, _locale|
|
|
19
|
+
validates name, length: { maximum: TITLE_MAX_LENGTH }, allow_blank: true, if: :validates_title?
|
|
20
|
+
end
|
|
21
|
+
translatable_attribute :introduction, String
|
|
22
|
+
attribute :position, Integer, default: 0
|
|
23
|
+
attribute :manifest_name, String
|
|
24
|
+
attribute :enabled, :boolean, default: true
|
|
25
|
+
|
|
26
|
+
validates :title, translatable_presence: true, if: :validates_title?
|
|
27
|
+
validates :manifest_name, presence: true
|
|
28
|
+
|
|
29
|
+
def validates_title?
|
|
30
|
+
true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def shows_title?
|
|
34
|
+
true
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def shows_introduction?
|
|
38
|
+
true
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def settings_hash
|
|
42
|
+
{}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def prefill_defaults!
|
|
46
|
+
# no-op; type forms override when they need locale defaults on #new
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def scope_name
|
|
50
|
+
"menu"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
protected
|
|
54
|
+
|
|
55
|
+
def translations_from(value)
|
|
56
|
+
return stringify_hash(value) if value.is_a?(Hash)
|
|
57
|
+
return {} if value.blank?
|
|
58
|
+
|
|
59
|
+
{ default_locale => value.to_s }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def stringify_hash(value)
|
|
63
|
+
value.to_h.stringify_keys
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def locale_keys
|
|
67
|
+
locales_organization.available_locales.map(&:to_s)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def default_locale
|
|
71
|
+
locales_organization.default_locale.to_s
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def locales_organization
|
|
75
|
+
current_organization || @mapped_organization
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
module MenuItems
|
|
7
|
+
class ComponentIdForm < MenuItemForm
|
|
8
|
+
MANIFESTS = {
|
|
9
|
+
"read_blogs" => "blogs",
|
|
10
|
+
"read_proposals" => "proposals",
|
|
11
|
+
"propose_proposals" => "proposals",
|
|
12
|
+
"vote_on_proposal" => "proposals"
|
|
13
|
+
}.freeze
|
|
14
|
+
|
|
15
|
+
attribute :component_id, Integer
|
|
16
|
+
|
|
17
|
+
validates :component_id, presence: true
|
|
18
|
+
validate :component_must_be_eligible
|
|
19
|
+
|
|
20
|
+
def map_model(model)
|
|
21
|
+
self.component_id = model.settings["component_id"]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def settings_hash
|
|
25
|
+
{ "component_id" => component_id }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def component_choices
|
|
29
|
+
eligible_components.map { |item| [item.hierarchy_title, item.id] }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def allowed_component_ids
|
|
35
|
+
eligible_components.map(&:id)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def component_must_be_eligible
|
|
39
|
+
return if allowed_component_ids.include?(component_id)
|
|
40
|
+
|
|
41
|
+
errors.add(:component_id, :inclusion)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def component_manifest
|
|
45
|
+
MANIFESTS.fetch(manifest_name)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
protected
|
|
49
|
+
|
|
50
|
+
def eligible_components
|
|
51
|
+
@eligible_components ||= Decidim::PublicComponents.for(
|
|
52
|
+
current_organization,
|
|
53
|
+
manifest_name: component_manifest
|
|
54
|
+
)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
module MenuItems
|
|
7
|
+
class ExitForm < MenuItemForm
|
|
8
|
+
translatable_attribute :response_label, String
|
|
9
|
+
|
|
10
|
+
validates :response_label, translatable_presence: true
|
|
11
|
+
|
|
12
|
+
def map_model(model)
|
|
13
|
+
@mapped_organization = model.chatbot.organization
|
|
14
|
+
self.response_label = translations_from(model.settings["response_label"])
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def settings_hash
|
|
18
|
+
{ "response_label" => translations_from(response_label) }
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
module MenuItems
|
|
7
|
+
class LoginForm < MenuItemForm
|
|
8
|
+
attribute :redirect_path, String
|
|
9
|
+
translatable_attribute :response_label, String
|
|
10
|
+
|
|
11
|
+
validates :redirect_path, presence: true
|
|
12
|
+
validates :redirect_path, format: { with: %r{\A/(?!/).*\z} }
|
|
13
|
+
validates :response_label, translatable_presence: true
|
|
14
|
+
|
|
15
|
+
def shows_introduction?
|
|
16
|
+
false
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def map_model(model)
|
|
20
|
+
@mapped_organization = model.chatbot.organization
|
|
21
|
+
self.redirect_path = model.settings["redirect_path"]
|
|
22
|
+
self.response_label = translations_from(model.settings["response_label"])
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def settings_hash
|
|
26
|
+
{
|
|
27
|
+
"redirect_path" => redirect_path,
|
|
28
|
+
"response_label" => translations_from(response_label)
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
module MenuItems
|
|
7
|
+
class ProposeProposalsForm < ComponentIdForm
|
|
8
|
+
include ProposeProposalsLabels
|
|
9
|
+
|
|
10
|
+
def map_model(model)
|
|
11
|
+
super
|
|
12
|
+
@mapped_organization = model.chatbot.organization
|
|
13
|
+
assign_label_translations(model.settings)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def settings_hash
|
|
17
|
+
super.merge(label_settings)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
module MenuItems
|
|
7
|
+
# Shared propose_proposals label attribute list (form, prefill, manifest, API).
|
|
8
|
+
module ProposeProposalsLabels
|
|
9
|
+
extend ActiveSupport::Concern
|
|
10
|
+
|
|
11
|
+
LABEL_KEYS = Decidim::Chatbot::MenuItemLabelKeys::PROPOSE_PROPOSALS
|
|
12
|
+
|
|
13
|
+
included do
|
|
14
|
+
LABEL_KEYS.each do |attr|
|
|
15
|
+
translatable_attribute attr, String
|
|
16
|
+
validates attr, translatable_presence: true
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def prefill_defaults!
|
|
21
|
+
LABEL_KEYS.each do |attr|
|
|
22
|
+
public_send(:"#{attr}=", translated_defaults_for(prefill_default_key(attr)))
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def assign_label_translations(settings)
|
|
29
|
+
LABEL_KEYS.each do |attr|
|
|
30
|
+
public_send(:"#{attr}=", translations_from(settings[attr.to_s]))
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def label_settings
|
|
35
|
+
LABEL_KEYS.index_with do |attr|
|
|
36
|
+
translations_from(public_send(attr))
|
|
37
|
+
end.transform_keys(&:to_s)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def prefill_default_key(attr)
|
|
41
|
+
"decidim.chatbot.admin.items.#{attr}_propose_proposals_default"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def translated_defaults_for(key)
|
|
45
|
+
locales_organization.available_locales.index_with do |locale|
|
|
46
|
+
I18n.t(key, locale:)
|
|
47
|
+
end.stringify_keys
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
module MenuItems
|
|
7
|
+
class ReadBlogsForm < ComponentIdForm
|
|
8
|
+
include ReadContentLabels
|
|
9
|
+
|
|
10
|
+
def map_model(model)
|
|
11
|
+
super
|
|
12
|
+
@mapped_organization = model.chatbot.organization
|
|
13
|
+
assign_label_translations(model.settings)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def settings_hash
|
|
17
|
+
super.merge(label_settings)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
module MenuItems
|
|
7
|
+
# Shared read_blogs / read_proposals label attributes (form, manifest, API).
|
|
8
|
+
module ReadContentLabels
|
|
9
|
+
extend ActiveSupport::Concern
|
|
10
|
+
|
|
11
|
+
LABEL_KEYS = Decidim::Chatbot::MenuItemLabelKeys::READ_CONTENT
|
|
12
|
+
|
|
13
|
+
included do
|
|
14
|
+
LABEL_KEYS.each do |attr|
|
|
15
|
+
translatable_attribute attr, String
|
|
16
|
+
validates attr, translatable_presence: true
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def prefill_defaults!
|
|
21
|
+
self.nothing_to_read_label = translated_defaults_for(nothing_to_read_default_key)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def assign_label_translations(settings)
|
|
27
|
+
LABEL_KEYS.each do |attr|
|
|
28
|
+
public_send(:"#{attr}=", translations_from(settings[attr.to_s]))
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def label_settings
|
|
33
|
+
LABEL_KEYS.index_with do |attr|
|
|
34
|
+
translations_from(public_send(attr))
|
|
35
|
+
end.transform_keys(&:to_s)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def nothing_to_read_default_key
|
|
39
|
+
"decidim.chatbot.admin.items.nothing_to_read_label_#{manifest_name}_default"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def translated_defaults_for(key)
|
|
43
|
+
locales_organization.available_locales.index_with do |locale|
|
|
44
|
+
I18n.t(key, locale:)
|
|
45
|
+
end.stringify_keys
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
module MenuItems
|
|
7
|
+
class ReadProposalsForm < ComponentIdForm
|
|
8
|
+
include ReadContentLabels
|
|
9
|
+
|
|
10
|
+
def map_model(model)
|
|
11
|
+
super
|
|
12
|
+
@mapped_organization = model.chatbot.organization
|
|
13
|
+
assign_label_translations(model.settings)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def settings_hash
|
|
17
|
+
super.merge(label_settings)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|