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,195 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "swagger_helper"
|
|
4
|
+
|
|
5
|
+
# Nested response `before` hooks are the rswag pattern for per-status setup.
|
|
6
|
+
# rubocop:disable RSpec/ScatteredSetup
|
|
7
|
+
RSpec.describe Decidim::Api::RestFull::Chatbot::ChatbotsController do
|
|
8
|
+
path "/chatbots" do
|
|
9
|
+
get "List chatbots" do
|
|
10
|
+
tags "Chatbot"
|
|
11
|
+
produces "application/json"
|
|
12
|
+
operationId "listChatbots"
|
|
13
|
+
description <<~DESC
|
|
14
|
+
List chatbots for the current organization (general + WhatsApp metas).
|
|
15
|
+
Paginated; body `meta` includes `page`, `per_page`, `has_more`, `next`, `prev`.
|
|
16
|
+
Filter with `filter[whatsapp_phone_id_eq]`, `filter[whatsapp_phone_number_eq]`,
|
|
17
|
+
or `filter[whatsapp_display_name_eq]`. Returns 501 when chatbot is disabled.
|
|
18
|
+
DESC
|
|
19
|
+
|
|
20
|
+
it_behaves_like "paginated params"
|
|
21
|
+
it_behaves_like "localized params"
|
|
22
|
+
it_behaves_like "filtered params", filter: "whatsapp_phone_id", item_schema: { type: :string }, only: :string
|
|
23
|
+
it_behaves_like "filtered params", filter: "whatsapp_phone_number", item_schema: { type: :string }, only: :string
|
|
24
|
+
it_behaves_like "filtered params", filter: "whatsapp_display_name", item_schema: { type: :string }, only: :string
|
|
25
|
+
|
|
26
|
+
describe_api_endpoint(
|
|
27
|
+
controller: Decidim::Api::RestFull::Chatbot::ChatbotsController,
|
|
28
|
+
action: :index,
|
|
29
|
+
security_types: [:credentialFlow, :impersonationFlow],
|
|
30
|
+
scopes: ["whatsapp"],
|
|
31
|
+
permissions: ["whatsapp.read"]
|
|
32
|
+
) do
|
|
33
|
+
# rubocop:disable RSpec/VariableName -- RestFull localized params use locales[]
|
|
34
|
+
let(:"locales[]") { %w(en) }
|
|
35
|
+
# rubocop:enable RSpec/VariableName
|
|
36
|
+
let!(:chatbot) { create(:chatbot, organization:, whatsapp_phone_id: "phone-match") }
|
|
37
|
+
let!(:other) { create(:chatbot, organization: create(:organization)) }
|
|
38
|
+
|
|
39
|
+
before { enable_chatbot!(organization) }
|
|
40
|
+
|
|
41
|
+
response "200", "Chatbots listed" do
|
|
42
|
+
produces "application/json"
|
|
43
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_index_response)
|
|
44
|
+
|
|
45
|
+
run_test!(example_template_id: :ok) do |example|
|
|
46
|
+
body = JSON.parse(example.body)
|
|
47
|
+
ids = body["data"].map { |item| item["id"] }
|
|
48
|
+
expect(ids).to include(chatbot.id.to_s)
|
|
49
|
+
expect(ids).not_to include(other.id.to_s)
|
|
50
|
+
expect(body.dig("meta", "page")).to eq(1)
|
|
51
|
+
expect(body["meta"]).to have_key("has_more")
|
|
52
|
+
expect(example.headers["ETag"]).to be_present
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
response "200", "Chatbots filtered by phone id" do
|
|
57
|
+
# rubocop:disable RSpec/VariableName
|
|
58
|
+
let(:"filter[whatsapp_phone_id_eq]") { "phone-match" }
|
|
59
|
+
# rubocop:enable RSpec/VariableName
|
|
60
|
+
let!(:sibling) { create(:chatbot, organization:, whatsapp_phone_id: "phone-other") }
|
|
61
|
+
|
|
62
|
+
produces "application/json"
|
|
63
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_index_response)
|
|
64
|
+
|
|
65
|
+
run_test!(example_template_id: :ok_filtered_phone_id) do |example|
|
|
66
|
+
ids = JSON.parse(example.body)["data"].map { |item| item["id"] }
|
|
67
|
+
expect(ids).to eq([chatbot.id.to_s])
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
response "501", "Chatbot disabled" do
|
|
72
|
+
before do
|
|
73
|
+
Decidim::Toggle.save_config!(organization, Decidim::Chatbot::MODULE_NAME, { "enabled" => false })
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
run_test!(example_template_id: :not_implemented) do |example|
|
|
77
|
+
expect(example).to have_http_status(:not_implemented)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
path "/chatbots/{id}" do
|
|
85
|
+
get "Show chatbot" do
|
|
86
|
+
tags "Chatbot"
|
|
87
|
+
produces "application/json"
|
|
88
|
+
operationId "showChatbot"
|
|
89
|
+
description <<~DESC
|
|
90
|
+
Show one chatbot with relationships to menu_items, notifications, and subscribed users.
|
|
91
|
+
Conditional GET supported via ETag. Returns 501 when chatbot is disabled.
|
|
92
|
+
DESC
|
|
93
|
+
parameter name: :id, in: :path, type: :string
|
|
94
|
+
|
|
95
|
+
it_behaves_like "localized params"
|
|
96
|
+
|
|
97
|
+
describe_api_endpoint(
|
|
98
|
+
controller: Decidim::Api::RestFull::Chatbot::ChatbotsController,
|
|
99
|
+
action: :show,
|
|
100
|
+
security_types: [:credentialFlow, :impersonationFlow],
|
|
101
|
+
scopes: ["whatsapp"],
|
|
102
|
+
permissions: ["whatsapp.read"]
|
|
103
|
+
) do
|
|
104
|
+
# rubocop:disable RSpec/VariableName
|
|
105
|
+
let(:"locales[]") { %w(en) }
|
|
106
|
+
# rubocop:enable RSpec/VariableName
|
|
107
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
108
|
+
let(:id) { chatbot.id.to_s }
|
|
109
|
+
|
|
110
|
+
before { enable_chatbot!(organization) }
|
|
111
|
+
|
|
112
|
+
response "200", "Chatbot found" do
|
|
113
|
+
produces "application/json"
|
|
114
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_item_response)
|
|
115
|
+
|
|
116
|
+
run_test!(example_template_id: :ok) do |example|
|
|
117
|
+
body = JSON.parse(example.body)
|
|
118
|
+
expect(body.dig("data", "id")).to eq(chatbot.id.to_s)
|
|
119
|
+
expect(body.dig("data", "attributes", "whatsapp_phone_id")).to eq(chatbot.whatsapp_phone_id)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
response "200", "Chatbot with full relationships" do
|
|
124
|
+
let!(:menu_item) { create(:chatbot_item, chatbot:, title: { "en" => "Login" }) }
|
|
125
|
+
let!(:notification) do
|
|
126
|
+
create(
|
|
127
|
+
:chatbot_item,
|
|
128
|
+
chatbot:,
|
|
129
|
+
scope: "notification",
|
|
130
|
+
manifest_name: "manual",
|
|
131
|
+
title: { "en" => "Manual" },
|
|
132
|
+
settings: { "template_id" => "hello_world" }
|
|
133
|
+
)
|
|
134
|
+
end
|
|
135
|
+
let!(:subscribed_user) do
|
|
136
|
+
create(:user, organization:, extended_data: { "whatsapp_phone_number" => "+15551112222" })
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
produces "application/json"
|
|
140
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_item_response)
|
|
141
|
+
|
|
142
|
+
run_test!(example_template_id: :ok_full) do |example|
|
|
143
|
+
rel = JSON.parse(example.body).dig("data", "relationships")
|
|
144
|
+
expect(rel["menu_items"]["data"].map { |r| r["id"] }).to include(menu_item.id.to_s)
|
|
145
|
+
expect(rel["notifications"]["data"].map { |r| r["id"] }).to include(notification.id.to_s)
|
|
146
|
+
expect(rel["users"]["data"].map { |r| r["id"] }).to include(subscribed_user.id.to_s)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
response "404", "Chatbot not found" do
|
|
151
|
+
let(:id) { "0" }
|
|
152
|
+
|
|
153
|
+
run_test!(example_template_id: :not_found) do |example|
|
|
154
|
+
expect(example).to have_http_status(:not_found)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
response "501", "Chatbot disabled" do
|
|
159
|
+
before do
|
|
160
|
+
Decidim::Toggle.save_config!(organization, Decidim::Chatbot::MODULE_NAME, { "enabled" => false })
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
run_test!(example_template_id: :not_implemented) do |example|
|
|
164
|
+
expect(example).to have_http_status(:not_implemented)
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Conditional GET (not exported as a separate ReDoc operation)
|
|
172
|
+
describe "conditional GET" do
|
|
173
|
+
it "returns 304 with matching ETag" do
|
|
174
|
+
organization = create(:organization)
|
|
175
|
+
host! organization.host
|
|
176
|
+
enable_chatbot!(organization)
|
|
177
|
+
chatbot = create(:chatbot, organization:)
|
|
178
|
+
api_client = create(:api_client, organization:, scopes: ["whatsapp"])
|
|
179
|
+
api_client.permissions = [api_client.permissions.build(permission: "whatsapp.read")]
|
|
180
|
+
api_client.save!
|
|
181
|
+
token = create(:oauth_access_token, scopes: "whatsapp", application: api_client)
|
|
182
|
+
headers = { "Authorization" => "Bearer #{token.token}", "Host" => organization.host }
|
|
183
|
+
path = "/api/rest_full/v#{Decidim::RestFull.major_minor_version}/chatbots/#{chatbot.id}"
|
|
184
|
+
|
|
185
|
+
get path, headers: headers # rubocop:disable Style/HashSyntax -- keep explicit for clarity
|
|
186
|
+
expect(response).to have_http_status(:ok)
|
|
187
|
+
etag = response.headers["ETag"]
|
|
188
|
+
expect(etag).to be_present
|
|
189
|
+
|
|
190
|
+
get path, headers: headers.merge("If-None-Match" => etag)
|
|
191
|
+
expect(response).to have_http_status(:not_modified)
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
# rubocop:enable RSpec/ScatteredSetup
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::Admin::Chatbots::NotificationsController do
|
|
6
|
+
let(:organization) { create(:organization, available_locales: %w(en)) }
|
|
7
|
+
let(:user) { create(:user, :admin, :confirmed, organization:) }
|
|
8
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
9
|
+
let!(:item) do
|
|
10
|
+
create(
|
|
11
|
+
:chatbot_item,
|
|
12
|
+
chatbot:,
|
|
13
|
+
scope: "notification",
|
|
14
|
+
manifest_name: "manual",
|
|
15
|
+
settings: {
|
|
16
|
+
"template_id" => { "en" => "1649483436030166" },
|
|
17
|
+
"variables" => { "en" => { "name" => "%{nickname}" } }
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
before do
|
|
23
|
+
enable_chatbot!(organization, "business_id" => "1241516778015058")
|
|
24
|
+
host! organization.host
|
|
25
|
+
sign_in user
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "renders the template id fields and WhatsApp Manager edit link" do
|
|
29
|
+
get decidim_admin_chatbot.edit_chatbot_notification_path(chatbot, item)
|
|
30
|
+
|
|
31
|
+
expect(response).to have_http_status(:ok)
|
|
32
|
+
expect(response.body).to include("1649483436030166")
|
|
33
|
+
expect(response.body).to include("Must exist on")
|
|
34
|
+
expect(response.body).to include("Message templates")
|
|
35
|
+
expect(response.body).to include(
|
|
36
|
+
"https://business.facebook.com/latest/whatsapp_manager/message_templates/?business_id=1241516778015058"
|
|
37
|
+
)
|
|
38
|
+
expect(response.body).to include("Edit template in WhatsApp Manager")
|
|
39
|
+
expect(response.body).to include(
|
|
40
|
+
"https://business.facebook.com/latest/whatsapp_manager/1649483436030166/?reason=business_access&business_id=1241516778015058"
|
|
41
|
+
)
|
|
42
|
+
expect(response.body).to include("Template modifications can take up to 3 days to be validated by Meta")
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe "Chatbot admin tenant isolation" do
|
|
6
|
+
let(:organization) { create(:organization) }
|
|
7
|
+
let(:other) { create(:organization) }
|
|
8
|
+
let(:user) { create(:user, :admin, :confirmed, organization:) }
|
|
9
|
+
let(:chatbot) { create(:chatbot, organization:) }
|
|
10
|
+
let!(:foreign) { create(:chatbot, organization: other, whatsapp_display_name: "FOREIGN_BOT_NAME") }
|
|
11
|
+
let!(:foreign_item) do
|
|
12
|
+
create(:chatbot_item, chatbot: foreign, title: { "en" => "FOREIGN_ITEM_TITLE" })
|
|
13
|
+
end
|
|
14
|
+
let!(:foreign_notice) do
|
|
15
|
+
create(
|
|
16
|
+
:chatbot_item,
|
|
17
|
+
chatbot: foreign,
|
|
18
|
+
scope: "notification",
|
|
19
|
+
manifest_name: "manual",
|
|
20
|
+
title: { "en" => "FOREIGN_NOTICE_TITLE" },
|
|
21
|
+
settings: { "template_id" => "1649483436030166" }
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
let!(:foreign_member) do
|
|
25
|
+
create(:user, organization: other, name: "FOREIGN_WHATSAPP_USER",
|
|
26
|
+
extended_data: { "whatsapp_phone_number" => "+1555999" })
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
before do
|
|
30
|
+
enable_chatbot!(organization)
|
|
31
|
+
enable_chatbot!(other)
|
|
32
|
+
host! organization.host
|
|
33
|
+
sign_in user, scope: :user
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "returns 404 for another organization's general tab" do
|
|
37
|
+
get decidim_admin_chatbot.edit_chatbot_general_path(foreign)
|
|
38
|
+
expect(response).to have_http_status(:not_found)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "returns 404 and does not update another organization's welcome message" do
|
|
42
|
+
original = foreign.welcome_message
|
|
43
|
+
patch decidim_admin_chatbot.chatbot_general_path(foreign),
|
|
44
|
+
params: { chatbot: { welcome_message_en: "Hacked" } }
|
|
45
|
+
expect(response).to have_http_status(:not_found)
|
|
46
|
+
expect(foreign.reload.welcome_message).to eq(original)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "returns 404 for another organization's WhatsApp tab" do
|
|
50
|
+
get decidim_admin_chatbot.chatbot_whatsapp_path(foreign)
|
|
51
|
+
expect(response).to have_http_status(:not_found)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "returns 404 for another organization's menu items" do
|
|
55
|
+
get decidim_admin_chatbot.chatbot_menu_items_path(foreign)
|
|
56
|
+
expect(response).to have_http_status(:not_found)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "returns 404 for another organization's menu item" do
|
|
60
|
+
get decidim_admin_chatbot.edit_chatbot_menu_item_path(foreign, foreign_item)
|
|
61
|
+
expect(response).to have_http_status(:not_found)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "returns 404 and does not update another organization's menu item" do
|
|
65
|
+
patch decidim_admin_chatbot.chatbot_menu_item_path(foreign, foreign_item),
|
|
66
|
+
params: { item: { title_en: "Hacked", manifest_name: "login", redirect_path: "/x" } }
|
|
67
|
+
expect(response).to have_http_status(:not_found)
|
|
68
|
+
expect(foreign_item.reload.title["en"]).to eq("FOREIGN_ITEM_TITLE")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "returns 404 when editing another chatbot's item through this chatbot" do
|
|
72
|
+
get decidim_admin_chatbot.edit_chatbot_menu_item_path(chatbot, foreign_item)
|
|
73
|
+
expect(response).to have_http_status(:not_found)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "returns 404 for another organization's notifications" do
|
|
77
|
+
get decidim_admin_chatbot.chatbot_notifications_path(foreign)
|
|
78
|
+
expect(response).to have_http_status(:not_found)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "returns 404 and does not update another organization's notification" do
|
|
82
|
+
patch decidim_admin_chatbot.chatbot_notification_path(foreign, foreign_notice),
|
|
83
|
+
params: { item: { title_en: "Hacked", manifest_name: "manual", template_id_en: "x" } }
|
|
84
|
+
expect(response).to have_http_status(:not_found)
|
|
85
|
+
expect(foreign_notice.reload.title["en"]).to eq("FOREIGN_NOTICE_TITLE")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "returns 404 for another organization's users" do
|
|
89
|
+
get decidim_admin_chatbot.chatbot_users_path(foreign)
|
|
90
|
+
expect(response).to have_http_status(:not_found)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "does not list another organization's WhatsApp users on this chatbot" do
|
|
94
|
+
get decidim_admin_chatbot.chatbot_users_path(chatbot)
|
|
95
|
+
expect(response).to have_http_status(:ok)
|
|
96
|
+
expect(response.body).not_to include("FOREIGN_WHATSAPP_USER")
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "returns 404 when unsubscribing a user from another organization" do
|
|
100
|
+
patch decidim_admin_chatbot.unsubscribe_chatbot_user_path(chatbot, foreign_member)
|
|
101
|
+
expect(response).to have_http_status(:not_found)
|
|
102
|
+
expect(foreign_member.reload.extended_data[chatbot.subscription_key]).to be_nil
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "refuses reorder ids that belong to another chatbot" do
|
|
106
|
+
put decidim_admin_chatbot.reorder_chatbot_menu_items_path(chatbot),
|
|
107
|
+
params: { order_ids: [foreign_item.id] },
|
|
108
|
+
as: :json
|
|
109
|
+
expect(response).to have_http_status(:bad_request)
|
|
110
|
+
expect(foreign_item.reload.position).to eq(0)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "returns 404 for an unknown menu type" do
|
|
114
|
+
get decidim_admin_chatbot.new_chatbot_menu_item_path(chatbot, manifest_name: "nope")
|
|
115
|
+
expect(response).to have_http_status(:not_found)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "returns 404 for another organization's notification test page" do
|
|
119
|
+
get decidim_admin_chatbot.test_chatbot_notification_path(foreign, foreign_notice)
|
|
120
|
+
expect(response).to have_http_status(:not_found)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "returns 404 and does not deliver another organization's notification" do
|
|
124
|
+
post decidim_admin_chatbot.deliver_chatbot_notification_path(foreign, foreign_notice),
|
|
125
|
+
params: { test: { phone_number: "+15551234567" } }
|
|
126
|
+
expect(response).to have_http_status(:not_found)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it "returns 404 when testing another chatbot's notification through this chatbot" do
|
|
130
|
+
get decidim_admin_chatbot.test_chatbot_notification_path(chatbot, foreign_notice)
|
|
131
|
+
expect(response).to have_http_status(:not_found)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe "Chatbot admin unsubscribe" do
|
|
6
|
+
let(:organization) { create(:organization) }
|
|
7
|
+
let(:user) { create(:user, :admin, :confirmed, organization:) }
|
|
8
|
+
let(:chatbot) { create(:chatbot, organization:) }
|
|
9
|
+
let(:member) do
|
|
10
|
+
create(:user, organization:, extended_data: { "whatsapp_phone_number" => "+15551212", "keep" => "yes" })
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
before do
|
|
14
|
+
enable_chatbot!(organization)
|
|
15
|
+
host! organization.host
|
|
16
|
+
sign_in user, scope: :user
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "sets only the keyed subscription flag to false" do
|
|
20
|
+
patch decidim_admin_chatbot.unsubscribe_chatbot_user_path(chatbot, member)
|
|
21
|
+
|
|
22
|
+
expect(response).to redirect_to(decidim_admin_chatbot.chatbot_users_path(chatbot))
|
|
23
|
+
member.reload
|
|
24
|
+
expect(member.extended_data["whatsapp_phone_number"]).to eq("+15551212")
|
|
25
|
+
expect(member.extended_data["keep"]).to eq("yes")
|
|
26
|
+
expect(member.extended_data[chatbot.subscription_key]).to be(false)
|
|
27
|
+
end
|
|
28
|
+
end
|