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,344 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "swagger_helper"
|
|
4
|
+
|
|
5
|
+
# rubocop:disable RSpec/ScatteredSetup
|
|
6
|
+
RSpec.describe Decidim::Api::RestFull::Chatbot::ChatbotMenuItemsController do
|
|
7
|
+
path "/chatbot_menu_items" do
|
|
8
|
+
get "List chatbot menu items" do
|
|
9
|
+
tags "Chatbot"
|
|
10
|
+
produces "application/json"
|
|
11
|
+
operationId "listChatbotMenuItems"
|
|
12
|
+
description <<~DESC
|
|
13
|
+
List menu items for all chatbots in the current organization.
|
|
14
|
+
Always ordered by `position` ASC then `id` ASC.
|
|
15
|
+
Filter with `filter[chatbot_id_eq]` and `filter[enabled_eq]`.
|
|
16
|
+
Paginated with body `meta` (`page`, `per_page`, `has_more`, `next`, `prev`).
|
|
17
|
+
DESC
|
|
18
|
+
|
|
19
|
+
it_behaves_like "paginated params"
|
|
20
|
+
it_behaves_like "localized params"
|
|
21
|
+
it_behaves_like "filtered params", filter: "chatbot_id", item_schema: { type: :integer }, only: :integer
|
|
22
|
+
parameter name: "filter[enabled_eq]", in: :query, schema: {
|
|
23
|
+
type: :boolean,
|
|
24
|
+
description: "Match enabled flag (true|false)"
|
|
25
|
+
}, required: false
|
|
26
|
+
|
|
27
|
+
describe_api_endpoint(
|
|
28
|
+
controller: Decidim::Api::RestFull::Chatbot::ChatbotMenuItemsController,
|
|
29
|
+
action: :index,
|
|
30
|
+
security_types: [:credentialFlow, :impersonationFlow],
|
|
31
|
+
scopes: ["whatsapp"],
|
|
32
|
+
permissions: ["whatsapp.read"]
|
|
33
|
+
) do
|
|
34
|
+
# rubocop:disable RSpec/VariableName
|
|
35
|
+
let(:"locales[]") { %w(en) }
|
|
36
|
+
# rubocop:enable RSpec/VariableName
|
|
37
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
38
|
+
let!(:second) { create(:chatbot_item, chatbot:, position: 1, title: { "en" => "Second" }) }
|
|
39
|
+
let!(:first) { create(:chatbot_item, chatbot:, position: 0, title: { "en" => "First" }) }
|
|
40
|
+
let!(:disabled) { create(:chatbot_item, :disabled, chatbot:, position: 2) }
|
|
41
|
+
let!(:foreign) { create(:chatbot_item, chatbot: create(:chatbot, organization: create(:organization))) }
|
|
42
|
+
|
|
43
|
+
before { enable_chatbot!(organization) }
|
|
44
|
+
|
|
45
|
+
response "200", "Menu items listed" do
|
|
46
|
+
produces "application/json"
|
|
47
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_menu_item_index_response)
|
|
48
|
+
|
|
49
|
+
run_test!(example_name: :ok) do |example|
|
|
50
|
+
body = JSON.parse(example.body)
|
|
51
|
+
ids = body["data"].map { |item| item["id"] }
|
|
52
|
+
expect(ids).to include(first.id.to_s, second.id.to_s, disabled.id.to_s)
|
|
53
|
+
expect(ids).not_to include(foreign.id.to_s)
|
|
54
|
+
expect(ids.index(first.id.to_s)).to be < ids.index(second.id.to_s)
|
|
55
|
+
expect(body.dig("meta", "page")).to eq(1)
|
|
56
|
+
expect(body.dig("meta", "has_more")).to be(false)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
response "200", "Menu items filtered" do
|
|
61
|
+
# rubocop:disable RSpec/VariableName
|
|
62
|
+
let(:"filter[chatbot_id_eq]") { chatbot.id }
|
|
63
|
+
let(:"filter[enabled_eq]") { true }
|
|
64
|
+
# rubocop:enable RSpec/VariableName
|
|
65
|
+
|
|
66
|
+
produces "application/json"
|
|
67
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_menu_item_index_response)
|
|
68
|
+
|
|
69
|
+
run_test!(example_name: :ok_filtered_chatbot_enabled) do |example|
|
|
70
|
+
ids = JSON.parse(example.body)["data"].map { |item| item["id"] }
|
|
71
|
+
expect(ids).to contain_exactly(first.id.to_s, second.id.to_s)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
response "501", "Chatbot disabled" do
|
|
76
|
+
before do
|
|
77
|
+
Decidim::Toggle.save_config!(organization, Decidim::Chatbot::MODULE_NAME, { "enabled" => false })
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
run_test!(example_name: :not_implemented) do |example|
|
|
81
|
+
expect(example).to have_http_status(:not_implemented)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
path "/chatbot_menu_items/{id}" do
|
|
89
|
+
get "Show chatbot menu item" do
|
|
90
|
+
tags "Chatbot"
|
|
91
|
+
produces "application/json"
|
|
92
|
+
operationId "showChatbotMenuItem"
|
|
93
|
+
description <<~DESC
|
|
94
|
+
Show one menu item. JSON:API `type` is `chatbot_menu_item_<manifest>`
|
|
95
|
+
(OpenAPI oneOf discriminator on top-level `type`).
|
|
96
|
+
ReDoc examples: one `:ok_*` response per menu manifest.
|
|
97
|
+
DESC
|
|
98
|
+
parameter name: :id, in: :path, type: :string
|
|
99
|
+
|
|
100
|
+
it_behaves_like "localized params"
|
|
101
|
+
|
|
102
|
+
describe_api_endpoint(
|
|
103
|
+
controller: Decidim::Api::RestFull::Chatbot::ChatbotMenuItemsController,
|
|
104
|
+
action: :show,
|
|
105
|
+
security_types: [:credentialFlow, :impersonationFlow],
|
|
106
|
+
scopes: ["whatsapp"],
|
|
107
|
+
permissions: ["whatsapp.read"]
|
|
108
|
+
) do
|
|
109
|
+
# rubocop:disable RSpec/VariableName
|
|
110
|
+
let(:"locales[]") { %w(en) }
|
|
111
|
+
# rubocop:enable RSpec/VariableName
|
|
112
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
113
|
+
# Default for shared 403/500 examples; each 200 overrides type.
|
|
114
|
+
let!(:item) { create(:chatbot_item, chatbot:) }
|
|
115
|
+
let(:id) { item.id.to_s }
|
|
116
|
+
|
|
117
|
+
before { enable_chatbot!(organization) }
|
|
118
|
+
|
|
119
|
+
response "200", "Login menu item" do
|
|
120
|
+
let!(:item) do
|
|
121
|
+
create(:chatbot_item, chatbot:, manifest_name: "login",
|
|
122
|
+
settings: {
|
|
123
|
+
"redirect_path" => "/users/sign_in",
|
|
124
|
+
"response_label" => { "en" => "Open {{login_url}}" }
|
|
125
|
+
})
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
produces "application/json"
|
|
129
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_menu_item_item_response)
|
|
130
|
+
|
|
131
|
+
run_test!(example_name: :ok_login) do |example|
|
|
132
|
+
data = JSON.parse(example.body)["data"]
|
|
133
|
+
expect(data["type"]).to eq("chatbot_menu_item_login")
|
|
134
|
+
expect(data.dig("attributes", "redirect_path")).to eq("/users/sign_in")
|
|
135
|
+
expect(data.dig("attributes", "response_label")).to eq("en" => "Open {{login_url}}")
|
|
136
|
+
expect(data["attributes"]).not_to have_key("confirm_label")
|
|
137
|
+
expect(data["attributes"]).not_to have_key("component_id")
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
response "200", "Exit menu item" do
|
|
142
|
+
let!(:item) do
|
|
143
|
+
create(:chatbot_item, chatbot:, manifest_name: "exit",
|
|
144
|
+
settings: { "response_label" => { "en" => "You are unsubscribed" } },
|
|
145
|
+
title: { "en" => "Exit" })
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
produces "application/json"
|
|
149
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_menu_item_item_response)
|
|
150
|
+
|
|
151
|
+
run_test!(example_name: :ok_exit) do |example|
|
|
152
|
+
data = JSON.parse(example.body)["data"]
|
|
153
|
+
expect(data["type"]).to eq("chatbot_menu_item_exit")
|
|
154
|
+
expect(data.dig("attributes", "response_label")).to eq("en" => "You are unsubscribed")
|
|
155
|
+
expect(data["attributes"]).not_to have_key("confirm_label")
|
|
156
|
+
expect(data["attributes"]).not_to have_key("redirect_path")
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
response "200", "Read blogs menu item" do
|
|
161
|
+
let!(:item) do
|
|
162
|
+
create(:chatbot_item, chatbot:, manifest_name: "read_blogs",
|
|
163
|
+
settings: {
|
|
164
|
+
"component_id" => 11,
|
|
165
|
+
"menu_button_label" => { "en" => "Back to menu" },
|
|
166
|
+
"read_more_button_label" => { "en" => "Read more" },
|
|
167
|
+
"nothing_to_read_label" => { "en" => "Nothing to read" }
|
|
168
|
+
},
|
|
169
|
+
title: { "en" => "Blogs" })
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
produces "application/json"
|
|
173
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_menu_item_item_response)
|
|
174
|
+
|
|
175
|
+
run_test!(example_name: :ok_read_blogs) do |example|
|
|
176
|
+
data = JSON.parse(example.body)["data"]
|
|
177
|
+
expect(data["type"]).to eq("chatbot_menu_item_read_blogs")
|
|
178
|
+
expect(data.dig("attributes", "component_id")).to eq(11)
|
|
179
|
+
expect(data.dig("attributes", "menu_button_label")).to eq("en" => "Back to menu")
|
|
180
|
+
expect(data.dig("attributes", "read_more_button_label")).to eq("en" => "Read more")
|
|
181
|
+
expect(data.dig("attributes", "nothing_to_read_label")).to eq("en" => "Nothing to read")
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
response "200", "Read proposals menu item" do
|
|
186
|
+
let!(:item) do
|
|
187
|
+
create(:chatbot_item, chatbot:, manifest_name: "read_proposals",
|
|
188
|
+
settings: {
|
|
189
|
+
"component_id" => 22,
|
|
190
|
+
"menu_button_label" => { "en" => "Back to menu" },
|
|
191
|
+
"read_more_button_label" => { "en" => "Read more" },
|
|
192
|
+
"nothing_to_read_label" => { "en" => "Nothing to read" }
|
|
193
|
+
},
|
|
194
|
+
title: { "en" => "Proposals" })
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
produces "application/json"
|
|
198
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_menu_item_item_response)
|
|
199
|
+
|
|
200
|
+
run_test!(example_name: :ok_read_proposals) do |example|
|
|
201
|
+
data = JSON.parse(example.body)["data"]
|
|
202
|
+
expect(data["type"]).to eq("chatbot_menu_item_read_proposals")
|
|
203
|
+
expect(data.dig("attributes", "component_id")).to eq(22)
|
|
204
|
+
expect(data.dig("attributes", "menu_button_label")).to eq("en" => "Back to menu")
|
|
205
|
+
expect(data.dig("attributes", "read_more_button_label")).to eq("en" => "Read more")
|
|
206
|
+
expect(data.dig("attributes", "nothing_to_read_label")).to eq("en" => "Nothing to read")
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
response "200", "Propose proposals menu item" do
|
|
211
|
+
let!(:item) do
|
|
212
|
+
create(:chatbot_item, chatbot:, manifest_name: "propose_proposals",
|
|
213
|
+
settings: {
|
|
214
|
+
"component_id" => 33,
|
|
215
|
+
"default_title_label" => { "en" => "{{id}} Anonymous proposal" },
|
|
216
|
+
"body_label" => { "en" => "Please write your proposal" },
|
|
217
|
+
"verification_label" => { "en" => "Thanks, here is your proposal:" },
|
|
218
|
+
"action_prompt_label" => { "en" => "What do you want to do with the proposal?" },
|
|
219
|
+
"save_button_label" => { "en" => "Save" },
|
|
220
|
+
"success_label" => { "en" => "Your proposal has been submitted" },
|
|
221
|
+
"withdraw_button_label" => { "en" => "Withdraw" },
|
|
222
|
+
"withdraw_success_label" => { "en" => "Your proposal has been withdrawn" },
|
|
223
|
+
"creation_not_enabled_label" => {
|
|
224
|
+
"en" => "Proposal creation is not available right now, please come back later."
|
|
225
|
+
},
|
|
226
|
+
"title_blank_label" => { "en" => "cannot be blank" },
|
|
227
|
+
"body_blank_label" => { "en" => "cannot be blank" },
|
|
228
|
+
"title_must_start_with_caps_label" => { "en" => "must start with a capital letter" },
|
|
229
|
+
"body_must_start_with_caps_label" => { "en" => "must start with a capital letter" },
|
|
230
|
+
"title_too_much_caps_label" => {
|
|
231
|
+
"en" => "is using too many capital letters (over 25% of the text)"
|
|
232
|
+
},
|
|
233
|
+
"body_too_much_caps_label" => {
|
|
234
|
+
"en" => "is using too many capital letters (over 25% of the text)"
|
|
235
|
+
},
|
|
236
|
+
"title_too_short_label" => { "en" => "is too short (under %{count} characters)" },
|
|
237
|
+
"body_too_short_label" => { "en" => "is too short (under %{count} characters)" },
|
|
238
|
+
"title_too_long_label" => { "en" => "is too long (maximum is %{count} characters)" },
|
|
239
|
+
"body_too_long_label" => { "en" => "is too long (maximum is %{count} characters)" },
|
|
240
|
+
"title_too_many_marks_label" => {
|
|
241
|
+
"en" => "is using too many consecutive punctuation marks (e.g. ! and ?)"
|
|
242
|
+
},
|
|
243
|
+
"body_too_many_marks_label" => {
|
|
244
|
+
"en" => "is using too many consecutive punctuation marks (e.g. ! and ?)"
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
title: { "en" => "Propose" })
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
produces "application/json"
|
|
251
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_menu_item_item_response)
|
|
252
|
+
|
|
253
|
+
run_test!(example_name: :ok_propose_proposals) do |example|
|
|
254
|
+
data = JSON.parse(example.body)["data"]
|
|
255
|
+
expect(data["type"]).to eq("chatbot_menu_item_propose_proposals")
|
|
256
|
+
expect(data.dig("attributes", "component_id")).to eq(33)
|
|
257
|
+
expect(data.dig("attributes", "default_title_label")).to eq("en" => "{{id}} Anonymous proposal")
|
|
258
|
+
expect(data.dig("attributes", "body_label")).to eq("en" => "Please write your proposal")
|
|
259
|
+
expect(data.dig("attributes", "verification_label")).to eq("en" => "Thanks, here is your proposal:")
|
|
260
|
+
expect(data.dig("attributes", "action_prompt_label")).to eq("en" => "What do you want to do with the proposal?")
|
|
261
|
+
expect(data.dig("attributes", "save_button_label")).to eq("en" => "Save")
|
|
262
|
+
expect(data.dig("attributes", "success_label")).to eq("en" => "Your proposal has been submitted")
|
|
263
|
+
expect(data.dig("attributes", "withdraw_button_label")).to eq("en" => "Withdraw")
|
|
264
|
+
expect(data.dig("attributes", "withdraw_success_label")).to eq("en" => "Your proposal has been withdrawn")
|
|
265
|
+
expect(data.dig("attributes", "creation_not_enabled_label")).to eq(
|
|
266
|
+
"en" => "Proposal creation is not available right now, please come back later."
|
|
267
|
+
)
|
|
268
|
+
expect(data.dig("attributes", "title_blank_label")).to eq("en" => "cannot be blank")
|
|
269
|
+
expect(data.dig("attributes", "body_blank_label")).to eq("en" => "cannot be blank")
|
|
270
|
+
expect(data.dig("attributes", "title_must_start_with_caps_label")).to eq(
|
|
271
|
+
"en" => "must start with a capital letter"
|
|
272
|
+
)
|
|
273
|
+
expect(data.dig("attributes", "body_must_start_with_caps_label")).to eq(
|
|
274
|
+
"en" => "must start with a capital letter"
|
|
275
|
+
)
|
|
276
|
+
expect(data.dig("attributes", "title_too_much_caps_label")).to eq(
|
|
277
|
+
"en" => "is using too many capital letters (over 25% of the text)"
|
|
278
|
+
)
|
|
279
|
+
expect(data.dig("attributes", "body_too_much_caps_label")).to eq(
|
|
280
|
+
"en" => "is using too many capital letters (over 25% of the text)"
|
|
281
|
+
)
|
|
282
|
+
expect(data.dig("attributes", "title_too_short_label")).to eq(
|
|
283
|
+
"en" => "is too short (under %{count} characters)"
|
|
284
|
+
)
|
|
285
|
+
expect(data.dig("attributes", "body_too_short_label")).to eq(
|
|
286
|
+
"en" => "is too short (under %{count} characters)"
|
|
287
|
+
)
|
|
288
|
+
expect(data.dig("attributes", "title_too_long_label")).to eq(
|
|
289
|
+
"en" => "is too long (maximum is %{count} characters)"
|
|
290
|
+
)
|
|
291
|
+
expect(data.dig("attributes", "body_too_long_label")).to eq(
|
|
292
|
+
"en" => "is too long (maximum is %{count} characters)"
|
|
293
|
+
)
|
|
294
|
+
expect(data.dig("attributes", "title_too_many_marks_label")).to eq(
|
|
295
|
+
"en" => "is using too many consecutive punctuation marks (e.g. ! and ?)"
|
|
296
|
+
)
|
|
297
|
+
expect(data.dig("attributes", "body_too_many_marks_label")).to eq(
|
|
298
|
+
"en" => "is using too many consecutive punctuation marks (e.g. ! and ?)"
|
|
299
|
+
)
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
response "200", "Vote on proposal menu item" do
|
|
304
|
+
let!(:item) do
|
|
305
|
+
create(:chatbot_item, chatbot:, manifest_name: "vote_on_proposal",
|
|
306
|
+
settings: {
|
|
307
|
+
"component_id" => 44,
|
|
308
|
+
"action_prompt_label" => { "en" => "Here the actions you can do:" },
|
|
309
|
+
"menu_button_label" => { "en" => "Back to menu" },
|
|
310
|
+
"menu_connector_label" => { "en" => "See more" },
|
|
311
|
+
"skip_menu_button" => { "en" => "Skip" },
|
|
312
|
+
"vote_label" => { "en" => "Support" }
|
|
313
|
+
},
|
|
314
|
+
title: { "en" => "Vote" })
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
produces "application/json"
|
|
318
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_menu_item_item_response)
|
|
319
|
+
|
|
320
|
+
run_test!(example_name: :ok_vote) do |example|
|
|
321
|
+
data = JSON.parse(example.body)["data"]
|
|
322
|
+
expect(data["type"]).to eq("chatbot_menu_item_vote_on_proposal")
|
|
323
|
+
expect(data.dig("attributes", "component_id")).to eq(44)
|
|
324
|
+
expect(data.dig("attributes", "action_prompt_label")).to eq("en" => "Here the actions you can do:")
|
|
325
|
+
expect(data.dig("attributes", "menu_button_label")).to eq("en" => "Back to menu")
|
|
326
|
+
expect(data.dig("attributes", "menu_connector_label")).to eq("en" => "See more")
|
|
327
|
+
expect(data.dig("attributes", "skip_menu_button")).to eq("en" => "Skip")
|
|
328
|
+
expect(data.dig("attributes", "vote_label")).to eq("en" => "Support")
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
response "404", "Menu item not found" do
|
|
333
|
+
let!(:item) { create(:chatbot_item, chatbot:) }
|
|
334
|
+
let(:id) { "0" }
|
|
335
|
+
|
|
336
|
+
run_test!(example_name: :not_found) do |example|
|
|
337
|
+
expect(example).to have_http_status(:not_found)
|
|
338
|
+
end
|
|
339
|
+
end
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
# rubocop:enable RSpec/ScatteredSetup
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "swagger_helper"
|
|
4
|
+
|
|
5
|
+
# rubocop:disable RSpec/ScatteredSetup
|
|
6
|
+
RSpec.describe Decidim::Api::RestFull::Chatbot::ChatbotUsersController do
|
|
7
|
+
path "/chatbot_users" do
|
|
8
|
+
get "List subscribed chatbot users" do
|
|
9
|
+
tags "Chatbot"
|
|
10
|
+
produces "application/json"
|
|
11
|
+
operationId "listChatbotUsers"
|
|
12
|
+
description <<~DESC
|
|
13
|
+
List Decidim users with a WhatsApp phone who are **subscribed**
|
|
14
|
+
(not opted out). Optional `filter[chatbot_id_eq]` limits to one chatbot;
|
|
15
|
+
without it, users subscribed to at least one organization chatbot.
|
|
16
|
+
Never lists phone holders who are unsubscribed from all matching chatbots.
|
|
17
|
+
DESC
|
|
18
|
+
|
|
19
|
+
it_behaves_like "paginated params"
|
|
20
|
+
it_behaves_like "filtered params", filter: "chatbot_id", item_schema: { type: :integer }, only: :integer
|
|
21
|
+
|
|
22
|
+
describe_api_endpoint(
|
|
23
|
+
controller: Decidim::Api::RestFull::Chatbot::ChatbotUsersController,
|
|
24
|
+
action: :index,
|
|
25
|
+
security_types: [:credentialFlow, :impersonationFlow],
|
|
26
|
+
scopes: ["whatsapp"],
|
|
27
|
+
permissions: ["whatsapp.read"]
|
|
28
|
+
) do
|
|
29
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
30
|
+
let!(:second_chatbot) { create(:chatbot, organization:) }
|
|
31
|
+
let!(:subscribed) do
|
|
32
|
+
create(:user, organization:, extended_data: { "whatsapp_phone_number" => "+15550001" })
|
|
33
|
+
end
|
|
34
|
+
let!(:unsubscribed) do
|
|
35
|
+
create(
|
|
36
|
+
:user,
|
|
37
|
+
organization:,
|
|
38
|
+
extended_data: {
|
|
39
|
+
"whatsapp_phone_number" => "+15550002",
|
|
40
|
+
chatbot.subscription_key => false,
|
|
41
|
+
second_chatbot.subscription_key => false
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
before { enable_chatbot!(organization) }
|
|
47
|
+
|
|
48
|
+
response "200", "Subscribed users listed" do
|
|
49
|
+
produces "application/json"
|
|
50
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_user_index_response)
|
|
51
|
+
|
|
52
|
+
run_test!(example_name: :ok_subscribed) do |example|
|
|
53
|
+
body = JSON.parse(example.body)
|
|
54
|
+
ids = body["data"].map { |item| item["id"] }
|
|
55
|
+
expect(ids).to include(subscribed.id.to_s)
|
|
56
|
+
expect(ids).not_to include(unsubscribed.id.to_s)
|
|
57
|
+
expect(body.dig("meta", "page")).to eq(1)
|
|
58
|
+
expect(body.dig("meta", "has_more")).to be(false)
|
|
59
|
+
attrs = body["data"].find { |item| item["id"] == subscribed.id.to_s }["attributes"]
|
|
60
|
+
expect(attrs["subscribed_chatbot_ids"]).to include(chatbot.id.to_s, second_chatbot.id.to_s)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
response "200", "Users filtered by chatbot" do
|
|
65
|
+
# rubocop:disable RSpec/VariableName
|
|
66
|
+
let(:"filter[chatbot_id_eq]") { chatbot.id }
|
|
67
|
+
# rubocop:enable RSpec/VariableName
|
|
68
|
+
|
|
69
|
+
produces "application/json"
|
|
70
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_user_index_response)
|
|
71
|
+
|
|
72
|
+
run_test!(example_name: :ok_filtered_chatbot) do |example|
|
|
73
|
+
ids = JSON.parse(example.body)["data"].map { |item| item["id"] }
|
|
74
|
+
expect(ids).to eq([subscribed.id.to_s])
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
response "501", "Chatbot disabled" do
|
|
79
|
+
before do
|
|
80
|
+
Decidim::Toggle.save_config!(organization, Decidim::Chatbot::MODULE_NAME, { "enabled" => false })
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
run_test!(example_name: :not_implemented) do |example|
|
|
84
|
+
expect(example).to have_http_status(:not_implemented)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
path "/chatbot_users/{id}" do
|
|
92
|
+
get "Show chatbot user" do
|
|
93
|
+
tags "Chatbot"
|
|
94
|
+
produces "application/json"
|
|
95
|
+
operationId "showChatbotUser"
|
|
96
|
+
description <<~DESC
|
|
97
|
+
Show a subscribed WhatsApp user: Decidim id, phone from extended_data,
|
|
98
|
+
and related Decidim::Identity rows when present.
|
|
99
|
+
DESC
|
|
100
|
+
parameter name: :id, in: :path, type: :string
|
|
101
|
+
|
|
102
|
+
describe_api_endpoint(
|
|
103
|
+
controller: Decidim::Api::RestFull::Chatbot::ChatbotUsersController,
|
|
104
|
+
action: :show,
|
|
105
|
+
security_types: [:credentialFlow, :impersonationFlow],
|
|
106
|
+
scopes: ["whatsapp"],
|
|
107
|
+
permissions: ["whatsapp.read"]
|
|
108
|
+
) do
|
|
109
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
110
|
+
let!(:user) do
|
|
111
|
+
create(:user, organization:, extended_data: { "whatsapp_phone_number" => "+15550001" })
|
|
112
|
+
end
|
|
113
|
+
let(:id) { user.id.to_s }
|
|
114
|
+
|
|
115
|
+
before { enable_chatbot!(organization) }
|
|
116
|
+
|
|
117
|
+
response "200", "User found" do
|
|
118
|
+
produces "application/json"
|
|
119
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_user_item_response)
|
|
120
|
+
|
|
121
|
+
run_test!(example_name: :ok_with_identities_empty) do |example|
|
|
122
|
+
data = JSON.parse(example.body)["data"]
|
|
123
|
+
expect(data["id"]).to eq(user.id.to_s)
|
|
124
|
+
expect(data.dig("attributes", "whatsapp_phone_number")).to eq("+15550001")
|
|
125
|
+
expect(data.dig("relationships", "identities", "data")).to eq([])
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
response "404", "User not found" do
|
|
130
|
+
let(:id) { "0" }
|
|
131
|
+
|
|
132
|
+
run_test!(example_name: :not_found) do |example|
|
|
133
|
+
expect(example).to have_http_status(:not_found)
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
# rubocop:enable RSpec/ScatteredSetup
|