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,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::Whatsapp::StatusMapper do
|
|
6
|
+
subject { described_class.call(details) }
|
|
7
|
+
|
|
8
|
+
let(:details) do
|
|
9
|
+
{
|
|
10
|
+
platform_type:,
|
|
11
|
+
subscribed_apps:,
|
|
12
|
+
health_status: {
|
|
13
|
+
"can_send_message" => can_send,
|
|
14
|
+
"entities" => [
|
|
15
|
+
{
|
|
16
|
+
"entity_type" => "PHONE_NUMBER",
|
|
17
|
+
"can_send_message" => can_send,
|
|
18
|
+
"errors" => errors
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
end
|
|
24
|
+
let(:platform_type) { "CLOUD_API" }
|
|
25
|
+
let(:subscribed_apps) { [{ "id" => "app-1" }] }
|
|
26
|
+
let(:can_send) { "AVAILABLE" }
|
|
27
|
+
let(:errors) { [] }
|
|
28
|
+
|
|
29
|
+
it { is_expected.to eq("ready") }
|
|
30
|
+
|
|
31
|
+
context "when blocked" do
|
|
32
|
+
let(:can_send) { "BLOCKED" }
|
|
33
|
+
|
|
34
|
+
it { is_expected.to eq("blocked") }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context "when waiting 2FA" do
|
|
38
|
+
let(:can_send) { "LIMITED" }
|
|
39
|
+
let(:errors) { [{ "error_code" => "133005" }] }
|
|
40
|
+
|
|
41
|
+
it { is_expected.to eq("waiting_2fa") }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context "when waiting confirmation" do
|
|
45
|
+
let(:can_send) { "LIMITED" }
|
|
46
|
+
let(:errors) { [{ "error_code" => "133010" }] }
|
|
47
|
+
|
|
48
|
+
it { is_expected.to eq("waiting_confirmation") }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context "when subscribed but not ready" do
|
|
52
|
+
let(:can_send) { "UNKNOWN" }
|
|
53
|
+
|
|
54
|
+
it { is_expected.to eq("subscribed") }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
context "when only created" do
|
|
58
|
+
let(:platform_type) { "NOT_APPLICABLE" }
|
|
59
|
+
let(:subscribed_apps) { [] }
|
|
60
|
+
let(:can_send) { "UNKNOWN" }
|
|
61
|
+
|
|
62
|
+
it { is_expected.to eq("created") }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot do
|
|
6
|
+
it "exposes a gem version" do
|
|
7
|
+
expect(described_class.version).to match(/\A\d+\.\d+\.\d+\z/)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "pins a Decidim version range" do
|
|
11
|
+
expect(described_class.decidim_version).to eq([">= 0.32", "< 0.33"])
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "pins the WhatsApp Graph API version" do
|
|
15
|
+
expect(described_class.whatsapp_api_version).to eq("v26.0")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "exposes the toggle module name" do
|
|
19
|
+
expect(described_class::MODULE_NAME).to eq("decidim_chatbot")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe ".enabled_for?" do
|
|
23
|
+
let(:organization) { create(:organization) }
|
|
24
|
+
|
|
25
|
+
it "is false by default" do
|
|
26
|
+
expect(described_class.enabled_for?(organization)).to be(false)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "is true when Toggle enabled is set" do
|
|
30
|
+
Decidim::Toggle.save_config!(
|
|
31
|
+
organization,
|
|
32
|
+
described_class::MODULE_NAME,
|
|
33
|
+
{ "enabled" => true }
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
expect(described_class.enabled_for?(organization)).to be(true)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "OpenAPI definitions" do
|
|
41
|
+
it "exposes chatbot OpenAPI objects and tags registered at boot" do
|
|
42
|
+
expect(
|
|
43
|
+
Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_attributes)
|
|
44
|
+
).to be_present
|
|
45
|
+
expect(
|
|
46
|
+
Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot)
|
|
47
|
+
).to be_present
|
|
48
|
+
expect(
|
|
49
|
+
Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_menu_item)
|
|
50
|
+
).to be_present
|
|
51
|
+
expect(
|
|
52
|
+
Decidim::RestFull::Core::DefinitionRegistry.reference(:chatbot_user)
|
|
53
|
+
).to be_present
|
|
54
|
+
expect(Decidim::RestFull::Definitions::Tags::CHATBOT[:name]).to eq("Chatbot")
|
|
55
|
+
expect(Decidim::RestFull::Definitions::Tags::CHATBOT[:description]).to include("whatsapp")
|
|
56
|
+
expect(Decidim::Chatbot::Chatbot::STATUSES).to include("ready")
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::Chatbot do
|
|
6
|
+
subject(:chatbot) { build(:chatbot) }
|
|
7
|
+
|
|
8
|
+
it { is_expected.to be_valid }
|
|
9
|
+
|
|
10
|
+
it "rejects unknown statuses" do
|
|
11
|
+
chatbot.whatsapp_phone_status = "nope"
|
|
12
|
+
expect(chatbot).not_to be_valid
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "scopes by organization" do
|
|
16
|
+
org = create(:organization)
|
|
17
|
+
other = create(:organization)
|
|
18
|
+
mine = create(:chatbot, organization: org)
|
|
19
|
+
create(:chatbot, organization: other)
|
|
20
|
+
|
|
21
|
+
expect(described_class.for_organization(org)).to eq([mine])
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::Item do
|
|
6
|
+
subject(:item) { build(:chatbot_item) }
|
|
7
|
+
|
|
8
|
+
it { is_expected.to be_valid }
|
|
9
|
+
|
|
10
|
+
it "rejects an unknown manifest" do
|
|
11
|
+
item.manifest_name = "nope"
|
|
12
|
+
expect(item).not_to be_valid
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "rejects a notification type in the menu scope" do
|
|
16
|
+
item.scope = "menu"
|
|
17
|
+
item.manifest_name = "phase"
|
|
18
|
+
expect(item).not_to be_valid
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "scopes items by menu or notification" do
|
|
22
|
+
chatbot = create(:chatbot)
|
|
23
|
+
menu = create(:chatbot_item, chatbot:, scope: "menu", manifest_name: "login")
|
|
24
|
+
notice = create(:chatbot_item, chatbot:, scope: "notification", manifest_name: "manual",
|
|
25
|
+
settings: { "template_id" => "1649483436030166" })
|
|
26
|
+
|
|
27
|
+
expect(chatbot.items.for_scope(:menu)).to eq([menu])
|
|
28
|
+
expect(chatbot.items.for_scope(:notification)).to eq([notice])
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "does not include another chatbot's items" do
|
|
32
|
+
mine = create(:chatbot)
|
|
33
|
+
other = create(:chatbot, organization: mine.organization)
|
|
34
|
+
own = create(:chatbot_item, chatbot: mine)
|
|
35
|
+
create(:chatbot_item, chatbot: other)
|
|
36
|
+
|
|
37
|
+
expect(mine.items).to contain_exactly(own)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "defaults to enabled" do
|
|
41
|
+
expect(item).to be_enabled
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "excludes disabled items from the enabled scope" do
|
|
45
|
+
chatbot = create(:chatbot)
|
|
46
|
+
on = create(:chatbot_item, chatbot:)
|
|
47
|
+
create(:chatbot_item, :disabled, chatbot:)
|
|
48
|
+
|
|
49
|
+
expect(chatbot.items.enabled).to eq([on])
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "reads variables for an organization locale" do
|
|
53
|
+
organization = create(:organization, available_locales: %w(en pt-BR), default_locale: "pt-BR")
|
|
54
|
+
chatbot = create(:chatbot, organization:)
|
|
55
|
+
item = create(
|
|
56
|
+
:chatbot_item,
|
|
57
|
+
chatbot:,
|
|
58
|
+
scope: "notification",
|
|
59
|
+
manifest_name: "manual",
|
|
60
|
+
settings: {
|
|
61
|
+
"variables" => {
|
|
62
|
+
"en" => { "city" => "Nairobi" },
|
|
63
|
+
"pt-BR" => { "city" => "São Paulo" }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
expect(item.variables_hash).to eq("city" => "São Paulo")
|
|
69
|
+
expect(item.variables_hash_for("en")).to eq("city" => "Nairobi")
|
|
70
|
+
expect(item.variables_hash_for("pt-BR")).to eq("city" => "São Paulo")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "reads a template id for the recipient locale with fallback" do
|
|
74
|
+
organization = create(:organization, available_locales: %w(en es), default_locale: "en")
|
|
75
|
+
chatbot = create(:chatbot, organization:)
|
|
76
|
+
item = create(
|
|
77
|
+
:chatbot_item,
|
|
78
|
+
chatbot:,
|
|
79
|
+
scope: "notification",
|
|
80
|
+
manifest_name: "manual",
|
|
81
|
+
settings: { "template_id" => { "en" => "1649483436030166", "es" => "1649483436030168" } }
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
expect(item.template_id).to eq("1649483436030166")
|
|
85
|
+
expect(item.template_id_for("es")).to eq("1649483436030168")
|
|
86
|
+
expect(item.template_id_for("fr")).to eq("1649483436030166")
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::AdminLog::ChatbotPresenter do
|
|
6
|
+
subject(:presenter) { described_class.new(action_log, view_helpers) }
|
|
7
|
+
|
|
8
|
+
let(:organization) { create(:organization) }
|
|
9
|
+
let(:user) { create(:user, :admin, organization:) }
|
|
10
|
+
let(:chatbot) { create(:chatbot, organization:) }
|
|
11
|
+
let(:view_helpers) { double("h").as_null_object }
|
|
12
|
+
let(:action) { "update" }
|
|
13
|
+
let(:action_log) do
|
|
14
|
+
Decidim::ActionLog.create!(
|
|
15
|
+
organization:,
|
|
16
|
+
user:,
|
|
17
|
+
action:,
|
|
18
|
+
resource: chatbot,
|
|
19
|
+
version: chatbot.versions.last,
|
|
20
|
+
extra: { "resource" => { "title" => chatbot.name } }
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
before do
|
|
25
|
+
Decidim.traceability.update!(chatbot, user, { name: { "en" => "Logged name" } })
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "is used as the ActionLog presenter for chatbots" do
|
|
29
|
+
expect(Decidim::Chatbot::Chatbot.log_presenter_class_for(:admin_log)).to eq(described_class)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
shared_examples "action_string for" do |action_name, i18n_key|
|
|
33
|
+
let(:action) { action_name }
|
|
34
|
+
|
|
35
|
+
it "maps #{action_name}" do
|
|
36
|
+
expect(presenter.send(:action_string)).to eq(i18n_key)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it_behaves_like "action_string for", "create", "decidim.admin_log.chatbot.create"
|
|
41
|
+
it_behaves_like "action_string for", "delete", "decidim.admin_log.chatbot.delete"
|
|
42
|
+
it_behaves_like "action_string for", "update", "decidim.admin_log.chatbot.update"
|
|
43
|
+
|
|
44
|
+
context "when the action is unknown" do
|
|
45
|
+
let(:action) { "unknown" }
|
|
46
|
+
|
|
47
|
+
it "returns a string" do
|
|
48
|
+
expect(presenter.send(:action_string)).to be_a(String)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "exposes i18n labels and diff fields" do
|
|
53
|
+
expect(presenter.send(:i18n_labels_scope)).to eq("activemodel.attributes.chatbot")
|
|
54
|
+
expect(presenter.send(:diff_fields_mapping)).to include(
|
|
55
|
+
name: :i18n,
|
|
56
|
+
welcome_message: :i18n,
|
|
57
|
+
menu_intro: :i18n,
|
|
58
|
+
menu_connector: :i18n,
|
|
59
|
+
error_404: :i18n,
|
|
60
|
+
error_502: :i18n,
|
|
61
|
+
error_401: :i18n
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Chatbot
|
|
7
|
+
module Admin
|
|
8
|
+
describe ProposalVoteMode do
|
|
9
|
+
subject { described_class.new(component) }
|
|
10
|
+
|
|
11
|
+
let(:organization) { create(:organization) }
|
|
12
|
+
let(:space) { create(:participatory_process, :published, :with_steps, organization:) }
|
|
13
|
+
|
|
14
|
+
context "with votes enabled" do
|
|
15
|
+
let(:component) { create(:proposal_component, :with_votes_enabled, participatory_space: space) }
|
|
16
|
+
|
|
17
|
+
it { is_expected.to be_votes_open }
|
|
18
|
+
it { is_expected.to be_simple_vote }
|
|
19
|
+
it { is_expected.not_to be_voting_cards }
|
|
20
|
+
it { is_expected.not_to be_abstention }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "with votes disabled" do
|
|
24
|
+
let(:component) { create(:proposal_component, :with_votes_disabled, participatory_space: space) }
|
|
25
|
+
|
|
26
|
+
it { is_expected.not_to be_votes_open }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "with votes blocked" do
|
|
30
|
+
let(:component) { create(:proposal_component, :with_votes_blocked, participatory_space: space) }
|
|
31
|
+
|
|
32
|
+
it { is_expected.not_to be_votes_open }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context "without a component" do
|
|
36
|
+
let(:component) { nil }
|
|
37
|
+
|
|
38
|
+
it { is_expected.not_to be_votes_open }
|
|
39
|
+
it { is_expected.not_to be_simple_vote }
|
|
40
|
+
it { is_expected.not_to be_voting_cards }
|
|
41
|
+
it { is_expected.not_to be_abstention }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context "when awesome voting cards are available" do
|
|
45
|
+
let(:component) { create(:proposal_component, :with_votes_enabled, participatory_space: space) }
|
|
46
|
+
let(:settings) { component.settings }
|
|
47
|
+
let(:show_abstain) { true }
|
|
48
|
+
|
|
49
|
+
before do
|
|
50
|
+
specs = Gem.loaded_specs.to_hash
|
|
51
|
+
allow(Gem).to receive(:loaded_specs).and_return(
|
|
52
|
+
specs.merge("decidim-decidim_awesome" => instance_double(Gem::Specification))
|
|
53
|
+
)
|
|
54
|
+
allow(component).to receive(:settings).and_return(settings)
|
|
55
|
+
allow(settings).to receive(:try).and_call_original
|
|
56
|
+
allow(settings).to receive(:try).with(:awesome_voting_manifest).and_return("voting_cards")
|
|
57
|
+
allow(settings).to receive(:try).with(:voting_cards_show_abstain).and_return(show_abstain)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it { is_expected.to be_voting_cards }
|
|
61
|
+
it { is_expected.not_to be_simple_vote }
|
|
62
|
+
it { is_expected.to be_abstention }
|
|
63
|
+
|
|
64
|
+
context "without abstain" do
|
|
65
|
+
let(:show_abstain) { false }
|
|
66
|
+
|
|
67
|
+
it { is_expected.to be_voting_cards }
|
|
68
|
+
it { is_expected.not_to be_abstention }
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::WhatsappUsers do
|
|
6
|
+
let(:organization) { create(:organization) }
|
|
7
|
+
let(:other) { create(:organization) }
|
|
8
|
+
let(:chatbot) { create(:chatbot, organization:) }
|
|
9
|
+
let!(:matched) do
|
|
10
|
+
create(:user, organization:, extended_data: { "whatsapp_phone_number" => "+15550001" })
|
|
11
|
+
end
|
|
12
|
+
let!(:plain) { create(:user, organization:) }
|
|
13
|
+
let!(:foreign) do
|
|
14
|
+
create(:user, organization: other, extended_data: { "whatsapp_phone_number" => "+15550002" })
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "returns only org users with a WhatsApp phone" do
|
|
18
|
+
expect(described_class.for(chatbot)).to eq([matched])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "does not require a subscription flag to appear" do
|
|
22
|
+
matched.update!(extended_data: matched.extended_data.merge(chatbot.subscription_key => false))
|
|
23
|
+
|
|
24
|
+
expect(described_class.for(chatbot)).to eq([matched.reload])
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "filters out unsubscribed users" do
|
|
28
|
+
matched.update!(extended_data: matched.extended_data.merge(chatbot.subscription_key => false))
|
|
29
|
+
|
|
30
|
+
expect(described_class.subscribed_for(chatbot)).to eq([])
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe ".subscribed_for_organization" do
|
|
34
|
+
let!(:second) { create(:chatbot, organization:) }
|
|
35
|
+
|
|
36
|
+
it "includes users subscribed to at least one chatbot" do
|
|
37
|
+
expect(described_class.subscribed_for_organization(organization)).to eq([matched])
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "excludes users unsubscribed from every org chatbot" do
|
|
41
|
+
matched.update!(
|
|
42
|
+
extended_data: matched.extended_data.merge(
|
|
43
|
+
chatbot.subscription_key => false,
|
|
44
|
+
second.subscription_key => false
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
expect(described_class.subscribed_for_organization(organization)).to eq([])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "keeps users still subscribed to another chatbot" do
|
|
52
|
+
matched.update!(extended_data: matched.extended_data.merge(chatbot.subscription_key => false))
|
|
53
|
+
|
|
54
|
+
expect(described_class.subscribed_for_organization(organization)).to eq([matched.reload])
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|