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,122 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::Whatsapp::CreateFromPhone do
|
|
6
|
+
subject(:command) { described_class.new(organization:, phone_id:, client:) }
|
|
7
|
+
|
|
8
|
+
let(:organization) { create(:organization) }
|
|
9
|
+
let(:phone_id) { "123456" }
|
|
10
|
+
let(:client) { instance_double(Decidim::Chatbot::Whatsapp::GraphClient) }
|
|
11
|
+
let(:details) do
|
|
12
|
+
{
|
|
13
|
+
id: phone_id,
|
|
14
|
+
verified_name: "Acme",
|
|
15
|
+
display_phone_number: "+15551212",
|
|
16
|
+
platform_type: "CLOUD_API",
|
|
17
|
+
subscribed_apps: [{ "id" => "1" }],
|
|
18
|
+
health_status: { "can_send_message" => "AVAILABLE", "entities" => [] }
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
before do
|
|
23
|
+
Decidim::Toggle.save_config!(
|
|
24
|
+
organization,
|
|
25
|
+
Decidim::Chatbot::MODULE_NAME,
|
|
26
|
+
{
|
|
27
|
+
"enabled" => true,
|
|
28
|
+
"access_token" => "token",
|
|
29
|
+
"business_id" => "biz"
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
allow(client).to receive(:fetch_phone).with(phone_id).and_return(details)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "creates a chatbot synced from Meta" do
|
|
36
|
+
expect { command.call }.to change(Decidim::Chatbot::Chatbot, :count).by(1)
|
|
37
|
+
|
|
38
|
+
chatbot = Decidim::Chatbot::Chatbot.last
|
|
39
|
+
expect(chatbot.whatsapp_display_name).to eq("Acme")
|
|
40
|
+
expect(chatbot.whatsapp_phone_number).to eq("+15551212")
|
|
41
|
+
expect(chatbot.whatsapp_phone_status).to eq("ready")
|
|
42
|
+
expect(chatbot.name[organization.default_locale.to_s]).to eq("Acme")
|
|
43
|
+
expect(chatbot.synced_at).to be_within(1.minute).of(Time.current)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context "when credentials are missing" do
|
|
47
|
+
before do
|
|
48
|
+
Decidim::Toggle.save_config!(
|
|
49
|
+
organization,
|
|
50
|
+
Decidim::Chatbot::MODULE_NAME,
|
|
51
|
+
{ "enabled" => true, "access_token" => "", "business_id" => "" }
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "broadcasts missing_credentials" do
|
|
56
|
+
expect { command.call }.to broadcast(:invalid, :missing_credentials)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
context "when the phone belongs to another organization" do
|
|
61
|
+
before { create(:chatbot, whatsapp_phone_id: phone_id) }
|
|
62
|
+
|
|
63
|
+
it "broadcasts phone_belongs_to_other_organization" do
|
|
64
|
+
expect { command.call }.to broadcast(:invalid, :phone_belongs_to_other_organization)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context "when Graph does not find the phone" do
|
|
69
|
+
before { allow(client).to receive(:fetch_phone).and_return(nil) }
|
|
70
|
+
|
|
71
|
+
it "broadcasts phone_not_found" do
|
|
72
|
+
expect { command.call }.to broadcast(:invalid, :phone_not_found)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
context "when Graph raises" do
|
|
77
|
+
before { allow(client).to receive(:fetch_phone).and_raise(StandardError, "boom") }
|
|
78
|
+
|
|
79
|
+
it "broadcasts graph_error" do
|
|
80
|
+
expect { command.call }.to broadcast(:invalid, :graph_error, "StandardError: boom")
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context "when the chatbot already exists for this organization" do
|
|
85
|
+
let!(:existing) do
|
|
86
|
+
create(
|
|
87
|
+
:chatbot,
|
|
88
|
+
organization:,
|
|
89
|
+
whatsapp_phone_id: phone_id,
|
|
90
|
+
name: { "en" => "Keep me" },
|
|
91
|
+
whatsapp_display_name: "Old"
|
|
92
|
+
)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "re-syncs WhatsApp fields and keeps the existing name" do
|
|
96
|
+
expect { command.call }.not_to change(Decidim::Chatbot::Chatbot, :count)
|
|
97
|
+
existing.reload
|
|
98
|
+
expect(existing.whatsapp_display_name).to eq("Acme")
|
|
99
|
+
expect(existing.name["en"]).to eq("Keep me")
|
|
100
|
+
expect(existing.synced_at).to be_within(1.minute).of(Time.current)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
context "when Meta sync is disabled" do
|
|
105
|
+
before do
|
|
106
|
+
Decidim::Toggle.save_config!(
|
|
107
|
+
organization,
|
|
108
|
+
Decidim::Chatbot::MODULE_NAME,
|
|
109
|
+
{
|
|
110
|
+
"enabled" => false,
|
|
111
|
+
"access_token" => "token",
|
|
112
|
+
"business_id" => "biz"
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "broadcasts disabled" do
|
|
118
|
+
expect { command.call }.to broadcast(:invalid, :disabled)
|
|
119
|
+
expect(Decidim::Chatbot::Chatbot.count).to eq(0)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::Whatsapp::SyncPhone do
|
|
6
|
+
subject(:command) { described_class.new(chatbot, client:) }
|
|
7
|
+
|
|
8
|
+
let(:organization) { create(:organization) }
|
|
9
|
+
let(:chatbot) { create(:chatbot, organization:, whatsapp_phone_id: "999", whatsapp_phone_status: "created") }
|
|
10
|
+
let(:client) { instance_double(Decidim::Chatbot::Whatsapp::GraphClient) }
|
|
11
|
+
let(:details) do
|
|
12
|
+
{
|
|
13
|
+
id: "999",
|
|
14
|
+
verified_name: "Synced",
|
|
15
|
+
display_phone_number: "+1999",
|
|
16
|
+
platform_type: "CLOUD_API",
|
|
17
|
+
subscribed_apps: [],
|
|
18
|
+
health_status: { "can_send_message" => "BLOCKED", "entities" => [] }
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
before do
|
|
23
|
+
Decidim::Toggle.save_config!(
|
|
24
|
+
organization,
|
|
25
|
+
Decidim::Chatbot::MODULE_NAME,
|
|
26
|
+
{
|
|
27
|
+
"enabled" => true,
|
|
28
|
+
"access_token" => "token",
|
|
29
|
+
"business_id" => "biz"
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
allow(client).to receive(:fetch_phone).with("999").and_return(details)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "updates WhatsApp fields and status" do
|
|
36
|
+
command.call
|
|
37
|
+
chatbot.reload
|
|
38
|
+
expect(chatbot.whatsapp_display_name).to eq("Synced")
|
|
39
|
+
expect(chatbot.whatsapp_phone_number).to eq("+1999")
|
|
40
|
+
expect(chatbot.whatsapp_phone_status).to eq("blocked")
|
|
41
|
+
expect(chatbot.synced_at).to be_within(1.minute).of(Time.current)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "updates synced_at on re-sync" do
|
|
45
|
+
chatbot.update!(synced_at: 2.hours.ago)
|
|
46
|
+
command.call
|
|
47
|
+
expect(chatbot.reload.synced_at).to be_within(1.minute).of(Time.current)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context "when the organization has chatbot disabled" do
|
|
51
|
+
before do
|
|
52
|
+
Decidim::Toggle.save_config!(
|
|
53
|
+
organization,
|
|
54
|
+
Decidim::Chatbot::MODULE_NAME,
|
|
55
|
+
{
|
|
56
|
+
"enabled" => false,
|
|
57
|
+
"access_token" => "token",
|
|
58
|
+
"business_id" => "biz"
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "still syncs Meta fields (enabled only gates admin/API/create)" do
|
|
64
|
+
expect { command.call }.to broadcast(:ok)
|
|
65
|
+
expect(chatbot.reload.whatsapp_display_name).to eq("Synced")
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
context "when credentials are missing and no client is passed" do
|
|
70
|
+
subject(:command) { described_class.new(chatbot) }
|
|
71
|
+
|
|
72
|
+
before do
|
|
73
|
+
Decidim::Toggle.save_config!(
|
|
74
|
+
organization,
|
|
75
|
+
Decidim::Chatbot::MODULE_NAME,
|
|
76
|
+
{ "enabled" => true, "access_token" => "", "business_id" => "" }
|
|
77
|
+
)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "broadcasts missing_credentials" do
|
|
81
|
+
expect { command.call }.to broadcast(:invalid, :missing_credentials)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context "when no client is passed but credentials exist" do
|
|
86
|
+
subject(:command) { described_class.new(chatbot) }
|
|
87
|
+
|
|
88
|
+
before do
|
|
89
|
+
Decidim::Toggle.save_config!(
|
|
90
|
+
organization,
|
|
91
|
+
Decidim::Chatbot::MODULE_NAME,
|
|
92
|
+
{ "enabled" => true, "access_token" => "token", "business_id" => "biz" }
|
|
93
|
+
)
|
|
94
|
+
allow(Decidim::Chatbot::Whatsapp::GraphClient).to receive(:new).and_return(client)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "builds a GraphClient from Toggle credentials" do
|
|
98
|
+
expect { command.call }.to broadcast(:ok)
|
|
99
|
+
expect(chatbot.reload.whatsapp_display_name).to eq("Synced")
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
context "when Graph raises" do
|
|
104
|
+
before { allow(client).to receive(:fetch_phone).and_raise(StandardError, "boom") }
|
|
105
|
+
|
|
106
|
+
it "broadcasts graph_error" do
|
|
107
|
+
expect { command.call }.to broadcast(:invalid, :graph_error, "StandardError: boom")
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::Admin::ChatbotsController do
|
|
6
|
+
routes { Decidim::Chatbot::AdminEngine.routes }
|
|
7
|
+
|
|
8
|
+
let(:organization) { create(:organization) }
|
|
9
|
+
let(:user) { create(:user, :admin, :confirmed, organization:) }
|
|
10
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
11
|
+
|
|
12
|
+
before do
|
|
13
|
+
enable_chatbot!(organization)
|
|
14
|
+
request.env["decidim.current_organization"] = organization
|
|
15
|
+
sign_in user, scope: :user
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "GET edit" do
|
|
19
|
+
it "redirects the old edit URL to General" do
|
|
20
|
+
get :edit, params: { id: chatbot.id }
|
|
21
|
+
|
|
22
|
+
expect(response).to redirect_to(edit_chatbot_general_path(chatbot))
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
FactoryBot.define do
|
|
4
|
+
factory :chatbot, class: "Decidim::Chatbot::Chatbot" do
|
|
5
|
+
organization { create(:organization) }
|
|
6
|
+
sequence(:whatsapp_phone_id) { |n| "phone-#{n}" }
|
|
7
|
+
whatsapp_display_name { "Demo Bot" }
|
|
8
|
+
whatsapp_phone_number { "+15550001111" }
|
|
9
|
+
whatsapp_phone_status { "created" }
|
|
10
|
+
name { { "en" => "Demo chatbot" } }
|
|
11
|
+
welcome_message { { "en" => "Hello **world**" } }
|
|
12
|
+
menu_intro { { "en" => "What actions do you want to do?" } }
|
|
13
|
+
menu_connector { { "en" => "or" } }
|
|
14
|
+
error_404 { { "en" => "Not found" } }
|
|
15
|
+
error_502 { { "en" => "Service unavailable" } }
|
|
16
|
+
error_401 { { "en" => "Unauthorized" } }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
factory :chatbot_item, class: "Decidim::Chatbot::Item" do
|
|
20
|
+
chatbot
|
|
21
|
+
scope { "menu" }
|
|
22
|
+
manifest_name { "login" }
|
|
23
|
+
title { { "en" => "Login" } }
|
|
24
|
+
introduction { { "en" => "Intro" } }
|
|
25
|
+
position { 0 }
|
|
26
|
+
settings do
|
|
27
|
+
{
|
|
28
|
+
"redirect_path" => "/users/sign_in",
|
|
29
|
+
"response_label" => { "en" => "Open {{login_url}}" }
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
enabled { true }
|
|
33
|
+
|
|
34
|
+
trait :disabled do
|
|
35
|
+
enabled { false }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
trait :notification do
|
|
39
|
+
scope { "notification" }
|
|
40
|
+
manifest_name { "manual" }
|
|
41
|
+
settings { { "template_id" => { "en" => "1649483436030166" }, "variables" => { "en" => { "name" => "Hi" } } } }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Chatbot
|
|
7
|
+
module Admin
|
|
8
|
+
describe ChatbotForm do
|
|
9
|
+
subject do
|
|
10
|
+
described_class.from_params(attributes).with_context(current_organization: organization)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:organization) { create(:organization) }
|
|
14
|
+
let(:attributes) { { welcome_message_en: "Hello" } }
|
|
15
|
+
|
|
16
|
+
it { is_expected.to be_valid }
|
|
17
|
+
|
|
18
|
+
context "when welcome message is blank" do
|
|
19
|
+
let(:attributes) { { welcome_message_en: "" } }
|
|
20
|
+
|
|
21
|
+
it { is_expected.to be_valid }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "when menu and error copy are blank" do
|
|
25
|
+
let(:attributes) do
|
|
26
|
+
{
|
|
27
|
+
welcome_message_en: "",
|
|
28
|
+
menu_intro_en: "",
|
|
29
|
+
menu_connector_en: "",
|
|
30
|
+
error_404_en: "",
|
|
31
|
+
error_502_en: "",
|
|
32
|
+
error_401_en: ""
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it { is_expected.to be_valid }
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Chatbot
|
|
7
|
+
module Admin
|
|
8
|
+
describe ConfigForm do
|
|
9
|
+
subject do
|
|
10
|
+
described_class.from_params(attributes).with_context(current_organization: organization)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:organization) { create(:organization) }
|
|
14
|
+
let(:attributes) do
|
|
15
|
+
{
|
|
16
|
+
enabled: true,
|
|
17
|
+
access_token: "tok",
|
|
18
|
+
business_id: "biz"
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it { is_expected.to be_valid }
|
|
23
|
+
|
|
24
|
+
it "exposes the toggle module name" do
|
|
25
|
+
expect(described_class.module_config_name).to eq(Decidim::Chatbot::MODULE_NAME)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Chatbot
|
|
7
|
+
module Admin
|
|
8
|
+
describe MenuItemForm do
|
|
9
|
+
subject do
|
|
10
|
+
described_class.from_params(attributes).with_context(current_organization: organization)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:organization) { create(:organization) }
|
|
14
|
+
let(:attributes) do
|
|
15
|
+
{ title_en: "Hello", introduction_en: "Intro", manifest_name: "login" }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it { is_expected.to be_valid }
|
|
19
|
+
|
|
20
|
+
it "defaults enabled to true" do
|
|
21
|
+
expect(subject.enabled).to be(true)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "keeps translated title and introduction" do
|
|
25
|
+
expect(subject.title["en"]).to eq("Hello")
|
|
26
|
+
expect(subject.introduction["en"]).to eq("Intro")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "when title is blank" do
|
|
30
|
+
let(:attributes) { { title_en: "", introduction_en: "Intro", manifest_name: "login" } }
|
|
31
|
+
|
|
32
|
+
it { is_expected.not_to be_valid }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context "when title is 20 characters" do
|
|
36
|
+
let(:attributes) { { title_en: "a" * 20, introduction_en: "Intro", manifest_name: "login" } }
|
|
37
|
+
|
|
38
|
+
it { is_expected.to be_valid }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context "when title is longer than 20 characters" do
|
|
42
|
+
let(:attributes) { { title_en: "a" * 21, introduction_en: "Intro", manifest_name: "login" } }
|
|
43
|
+
|
|
44
|
+
it { is_expected.not_to be_valid }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Chatbot
|
|
7
|
+
module Admin
|
|
8
|
+
module MenuItems
|
|
9
|
+
describe ComponentIdForm do
|
|
10
|
+
subject do
|
|
11
|
+
ReadBlogsForm.from_params(attributes).with_context(current_organization: organization)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:organization) { create(:organization) }
|
|
15
|
+
let(:space) { create(:participatory_process, :published, organization:) }
|
|
16
|
+
let!(:component) { create(:post_component, participatory_space: space) }
|
|
17
|
+
let(:attributes) do
|
|
18
|
+
{
|
|
19
|
+
title_en: "Blogs",
|
|
20
|
+
introduction_en: "Intro",
|
|
21
|
+
manifest_name: "read_blogs",
|
|
22
|
+
component_id: component.id,
|
|
23
|
+
menu_button_label_en: "Back to menu",
|
|
24
|
+
read_more_button_label_en: "Read more",
|
|
25
|
+
nothing_to_read_label_en: "Nothing to read"
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it { is_expected.to be_valid }
|
|
30
|
+
|
|
31
|
+
it "lists only published blogs in published spaces" do
|
|
32
|
+
unpublished_component = create(:post_component, :unpublished, participatory_space: space)
|
|
33
|
+
unpublished_space = create(:participatory_process, :unpublished, organization:)
|
|
34
|
+
hidden = create(:post_component, participatory_space: unpublished_space)
|
|
35
|
+
other_org = create(:organization)
|
|
36
|
+
other_space = create(:participatory_process, :published, organization: other_org)
|
|
37
|
+
foreign = create(:post_component, participatory_space: other_space)
|
|
38
|
+
proposals = create(:proposal_component, participatory_space: space)
|
|
39
|
+
|
|
40
|
+
ids = subject.component_choices.map(&:last)
|
|
41
|
+
expect(ids).to include(component.id)
|
|
42
|
+
expect(ids).not_to include(unpublished_component.id, hidden.id, foreign.id, proposals.id)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "rejects a component that is not eligible" do
|
|
46
|
+
subject.component_id = create(:post_component, :unpublished, participatory_space: space).id
|
|
47
|
+
expect(subject).not_to be_valid
|
|
48
|
+
expect(subject.errors[:component_id]).to be_present
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|