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
data/crowdin.yml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Crowdin — set api_token / project_id via CI or local env as needed.
|
|
2
|
+
#
|
|
3
|
+
base_path: .
|
|
4
|
+
base_url: https://api.crowdin.com
|
|
5
|
+
api_token: "insecure_api_token"
|
|
6
|
+
project_id: "project_id"
|
|
7
|
+
|
|
8
|
+
preserve_hierarchy: true
|
|
9
|
+
|
|
10
|
+
files: [
|
|
11
|
+
{
|
|
12
|
+
"source": "/config/locales/decidim_chatbot.en.yml",
|
|
13
|
+
"translation": "/config/locales/decidim_chatbot_%two_letters_code%.yml",
|
|
14
|
+
}
|
|
15
|
+
]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class CreateDecidimChatbotChatbots < ActiveRecord::Migration[7.0]
|
|
4
|
+
def change
|
|
5
|
+
create_table :decidim_chatbot_chatbots do |t|
|
|
6
|
+
t.references :decidim_organization, null: false, foreign_key: { to_table: :decidim_organizations }, index: true
|
|
7
|
+
t.string :whatsapp_phone_id, null: false
|
|
8
|
+
t.string :whatsapp_display_name
|
|
9
|
+
t.string :whatsapp_phone_number
|
|
10
|
+
t.string :whatsapp_phone_status, null: false, default: "created"
|
|
11
|
+
t.jsonb :name, null: false, default: {}
|
|
12
|
+
t.jsonb :welcome_message, null: false, default: {}
|
|
13
|
+
t.datetime :synced_at
|
|
14
|
+
|
|
15
|
+
t.timestamps
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
add_index :decidim_chatbot_chatbots, :whatsapp_phone_id, unique: true
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class CreateDecidimChatbotItems < ActiveRecord::Migration[7.0]
|
|
4
|
+
def change
|
|
5
|
+
create_table :decidim_chatbot_items do |t|
|
|
6
|
+
t.references :decidim_chatbot, null: false, foreign_key: { to_table: :decidim_chatbot_chatbots }, index: true
|
|
7
|
+
t.string :scope, null: false
|
|
8
|
+
t.string :manifest_name, null: false
|
|
9
|
+
t.jsonb :title, null: false, default: {}
|
|
10
|
+
t.jsonb :introduction, null: false, default: {}
|
|
11
|
+
t.integer :position, null: false, default: 0
|
|
12
|
+
t.jsonb :settings, null: false, default: {}
|
|
13
|
+
|
|
14
|
+
t.timestamps
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
add_index :decidim_chatbot_items, [:decidim_chatbot_id, :scope, :position],
|
|
18
|
+
name: "index_decidim_chatbot_items_on_chatbot_scope_position"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class AddMenuAndErrorCopyToDecidimChatbotChatbots < ActiveRecord::Migration[7.0]
|
|
4
|
+
def change
|
|
5
|
+
change_table :decidim_chatbot_chatbots, bulk: true do |t|
|
|
6
|
+
t.jsonb :menu_intro, null: false, default: {}
|
|
7
|
+
t.jsonb :menu_connector, null: false, default: {}
|
|
8
|
+
t.jsonb :error_404, null: false, default: {}
|
|
9
|
+
t.jsonb :error_502, null: false, default: {}
|
|
10
|
+
t.jsonb :error_401, null: false, default: {}
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.push File.expand_path("lib", __dir__)
|
|
4
|
+
|
|
5
|
+
require "decidim/chatbot/version"
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |s|
|
|
8
|
+
s.version = Decidim::Chatbot.version
|
|
9
|
+
s.authors = ["hadrien@octree.ch"]
|
|
10
|
+
s.email = ["hadrien@octree.ch"]
|
|
11
|
+
s.license = "AGPL-3.0"
|
|
12
|
+
s.homepage = "https://octree-gva.github.io/decidim-chatbot"
|
|
13
|
+
s.required_ruby_version = ">= 3.4"
|
|
14
|
+
s.name = "decidim-chatbot"
|
|
15
|
+
s.summary = "WhatsApp chatbot administration and RestFull API for Decidim"
|
|
16
|
+
s.description = "Decidim module: Configuration > Settings > Chatbot admin surface " \
|
|
17
|
+
"and RestFull Extension endpoints for chatbot configuration."
|
|
18
|
+
|
|
19
|
+
s.files = Dir.chdir(__dir__) do
|
|
20
|
+
tracked = `git ls-files -z 2>/dev/null`.split("\x0").reject(&:empty?)
|
|
21
|
+
if tracked.any?
|
|
22
|
+
tracked
|
|
23
|
+
else
|
|
24
|
+
Dir["{app,config,lib,openapi}/**/*", "Rakefile", "README.md", "CONTRIBUTING.md"].select do |f|
|
|
25
|
+
File.file?(f)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
s.require_paths = ["lib"]
|
|
31
|
+
|
|
32
|
+
s.add_dependency "decidim-admin", Decidim::Chatbot.decidim_version
|
|
33
|
+
s.add_dependency "decidim-core", Decidim::Chatbot.decidim_version
|
|
34
|
+
s.add_dependency "decidim-restfull-blogs", "~> 0.3.11"
|
|
35
|
+
s.add_dependency "decidim-restfull-core", "~> 0.3.11"
|
|
36
|
+
s.add_dependency "decidim-restfull-proposals", "~> 0.3.11"
|
|
37
|
+
s.add_dependency "decidim-toggle", "~> 0.1.3"
|
|
38
|
+
|
|
39
|
+
s.metadata["rubygems_mfa_required"] = "true"
|
|
40
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Reproduces GitLab CI ruby::rspec: ruby:3.4.7 + postgres:17 + redis.
|
|
2
|
+
# Usage:
|
|
3
|
+
# docker compose -f docker-compose.ci.yml run --rm rspec
|
|
4
|
+
# docker compose -f docker-compose.ci.yml run --rm ci
|
|
5
|
+
x-ci-app: &ci-app
|
|
6
|
+
image: ruby:3.4.7
|
|
7
|
+
working_dir: /app
|
|
8
|
+
volumes:
|
|
9
|
+
- .:/app
|
|
10
|
+
- ../decidim-restfull:/home/decidim-restfull
|
|
11
|
+
shm_size: "2gb"
|
|
12
|
+
environment:
|
|
13
|
+
DATABASE_HOST: postgres
|
|
14
|
+
DATABASE_PASSWORD: "TEST-insecure_password"
|
|
15
|
+
DATABASE_USERNAME: decidim
|
|
16
|
+
DISABLED_DOCKER_COMPOSE: "true"
|
|
17
|
+
TRAEFIK_REDIS_URL: "redis://redis:6379/1"
|
|
18
|
+
NODE_MAJOR: "22"
|
|
19
|
+
SIMPLECOV: "1"
|
|
20
|
+
CI: "1"
|
|
21
|
+
DECIDIM_FORCE_SSL: "false"
|
|
22
|
+
DECIDIM_RESTFULL_PATH: /home/decidim-restfull
|
|
23
|
+
DISABLE_SPRING: "1"
|
|
24
|
+
depends_on:
|
|
25
|
+
postgres:
|
|
26
|
+
condition: service_healthy
|
|
27
|
+
redis:
|
|
28
|
+
condition: service_started
|
|
29
|
+
entrypoint: []
|
|
30
|
+
|
|
31
|
+
services:
|
|
32
|
+
postgres:
|
|
33
|
+
image: postgres:17
|
|
34
|
+
environment:
|
|
35
|
+
POSTGRES_DB: decidim_test
|
|
36
|
+
POSTGRES_USER: decidim
|
|
37
|
+
POSTGRES_PASSWORD: "TEST-insecure_password"
|
|
38
|
+
healthcheck:
|
|
39
|
+
test: ["CMD-SHELL", "pg_isready -U decidim -d decidim_test"]
|
|
40
|
+
interval: 2s
|
|
41
|
+
timeout: 5s
|
|
42
|
+
retries: 10
|
|
43
|
+
|
|
44
|
+
redis:
|
|
45
|
+
image: redis:latest
|
|
46
|
+
|
|
47
|
+
rspec:
|
|
48
|
+
<<: *ci-app
|
|
49
|
+
command:
|
|
50
|
+
- /bin/bash
|
|
51
|
+
- -c
|
|
52
|
+
- bin/ci-setup && unset DATABASE_URL && RAILS_ENV=test bundle exec rspec
|
|
53
|
+
|
|
54
|
+
ci:
|
|
55
|
+
<<: *ci-app
|
|
56
|
+
command:
|
|
57
|
+
- /bin/bash
|
|
58
|
+
- -c
|
|
59
|
+
- bin/ci-setup && unset DATABASE_URL && ./bin/check && (cd website && yarn install && yarn build)
|
data/docker-compose.yml
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Sibling RestFull mount is for bin/gen-openapi (filesystem merge), not Bundler.
|
|
2
|
+
# Override with DECIDIM_RESTFULL_PATH if the monorepo lives elsewhere (default below).
|
|
3
|
+
services:
|
|
4
|
+
chatbot:
|
|
5
|
+
command: bash -c "sleep infinity"
|
|
6
|
+
image: octree/decidim-dev:0.32
|
|
7
|
+
entrypoint: ""
|
|
8
|
+
working_dir: /home/module
|
|
9
|
+
volumes:
|
|
10
|
+
- .:/home/module
|
|
11
|
+
- ../decidim-restfull:/home/decidim-restfull
|
|
12
|
+
- bundle:/home/decidim/vendor
|
|
13
|
+
- node_modules:/home/decidim/node_modules
|
|
14
|
+
environment:
|
|
15
|
+
- PORT=3000
|
|
16
|
+
- DATABASE_URL=postgresql://decidim:pleaseChangeMe@chatbot-db:5432/decidim
|
|
17
|
+
- DATABASE_HOST=chatbot-db
|
|
18
|
+
- DATABASE_USERNAME=decidim
|
|
19
|
+
- DATABASE_PASSWORD=pleaseChangeMe
|
|
20
|
+
- DEV_MODULE=decidim-chatbot
|
|
21
|
+
- DECIDIM_RESTFULL_PATH=/home/decidim-restfull
|
|
22
|
+
- RAILS_ENV=development
|
|
23
|
+
- DISABLED_DOCKER_COMPOSE=true
|
|
24
|
+
- DECIDIM_FORCE_SSL=false
|
|
25
|
+
- RAILS_FORCE_SSL=false
|
|
26
|
+
- DISABLE_SPRING=1
|
|
27
|
+
depends_on:
|
|
28
|
+
- chatbot-db
|
|
29
|
+
ports:
|
|
30
|
+
- 3010:3000
|
|
31
|
+
- 3035:3035
|
|
32
|
+
links:
|
|
33
|
+
- chatbot-db
|
|
34
|
+
|
|
35
|
+
chatbot-db:
|
|
36
|
+
image: postgres:17
|
|
37
|
+
volumes:
|
|
38
|
+
- chatbot-pg-data:/var/lib/postgresql/data
|
|
39
|
+
environment:
|
|
40
|
+
- POSTGRES_DATABASE=decidim
|
|
41
|
+
- POSTGRES_USER=decidim
|
|
42
|
+
- POSTGRES_PASSWORD=pleaseChangeMe
|
|
43
|
+
|
|
44
|
+
volumes:
|
|
45
|
+
node_modules: {}
|
|
46
|
+
bundle: {}
|
|
47
|
+
chatbot-pg-data: {}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
module Admin
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class AdminEngine < ::Rails::Engine
|
|
9
|
+
isolate_namespace Decidim::Chatbot::Admin
|
|
10
|
+
|
|
11
|
+
routes do
|
|
12
|
+
resources :chatbots, only: [:index, :edit] do
|
|
13
|
+
resource :general, only: [:edit, :update], controller: "chatbots/generals"
|
|
14
|
+
resource :whatsapp, only: [:show], controller: "chatbots/whatsapps" do
|
|
15
|
+
post :sync
|
|
16
|
+
post :link
|
|
17
|
+
end
|
|
18
|
+
resources :menu_items, controller: "chatbots/menu_items" do
|
|
19
|
+
collection do
|
|
20
|
+
put :reorder
|
|
21
|
+
patch :reorder
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
resources :notifications, controller: "chatbots/notifications" do
|
|
25
|
+
member do
|
|
26
|
+
get :test
|
|
27
|
+
post :test
|
|
28
|
+
post :deliver
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
resources :users, only: [:index], controller: "chatbots/users" do
|
|
32
|
+
member { patch :unsubscribe }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
root to: "chatbots#index"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
initializer "decidim_chatbot.admin_mount_routes" do
|
|
39
|
+
Decidim::Core::Engine.routes do
|
|
40
|
+
extend Decidim::Routes::LocaleRedirects
|
|
41
|
+
|
|
42
|
+
scope "/:locale", **locale_scope_options do
|
|
43
|
+
mount Decidim::Chatbot::AdminEngine, at: "/admin/chatbot", as: "decidim_admin_chatbot"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
initializer "decidim_chatbot.admin_settings_menu" do
|
|
49
|
+
Decidim.menu :admin_settings_menu do |menu|
|
|
50
|
+
menu.add_item :chatbot,
|
|
51
|
+
I18n.t("decidim.chatbot.admin.menu.chatbot"),
|
|
52
|
+
decidim_admin_chatbot.root_path,
|
|
53
|
+
icon_name: "whatsapp-line",
|
|
54
|
+
position: 99,
|
|
55
|
+
active: is_active_link?(decidim_admin_chatbot.root_path, :inclusive),
|
|
56
|
+
if: Decidim::Chatbot.enabled_for?(current_organization)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
initializer "decidim_chatbot.admin_chatbot_menu" do
|
|
61
|
+
Decidim.menu :admin_chatbot_menu do |menu|
|
|
62
|
+
Decidim::Chatbot::AdminMenu.register(menu, @chatbot, self)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
# Builds :admin_chatbot_menu items for the duplicated Main tabs chrome.
|
|
6
|
+
class AdminMenu
|
|
7
|
+
def self.register(menu, chatbot, view)
|
|
8
|
+
new(menu, chatbot, view).register
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def initialize(menu, chatbot, view)
|
|
12
|
+
@menu = menu
|
|
13
|
+
@chatbot = chatbot
|
|
14
|
+
@view = view
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def register
|
|
18
|
+
return unless chatbot
|
|
19
|
+
|
|
20
|
+
add_tab(:general, :settings_4_line, view.edit_chatbot_general_path(chatbot))
|
|
21
|
+
add_tab(:whatsapp, :whatsapp_line, view.chatbot_whatsapp_path(chatbot))
|
|
22
|
+
add_tab(:menu, :menu_line, view.chatbot_menu_items_path(chatbot))
|
|
23
|
+
add_tab(:notification, :notification_3_line, view.chatbot_notifications_path(chatbot))
|
|
24
|
+
add_tab(:users, :group_line, view.chatbot_users_path(chatbot))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
attr_reader :menu, :chatbot, :view
|
|
30
|
+
|
|
31
|
+
def add_tab(key, icon, path)
|
|
32
|
+
menu.add_item key, label(key), path, icon_name: icon.to_s.tr("_", "-"),
|
|
33
|
+
active: view.is_active_link?(path, :inclusive)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def label(key)
|
|
37
|
+
I18n.t(key, scope: "decidim.chatbot.admin.menu.tabs")
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
# Registers the six menu types and two notification types once at boot.
|
|
6
|
+
module DefaultManifests
|
|
7
|
+
module_function
|
|
8
|
+
|
|
9
|
+
def register!
|
|
10
|
+
return if Decidim::Chatbot.registry.for(:menu).any?
|
|
11
|
+
|
|
12
|
+
register_component_menus
|
|
13
|
+
register_string_menus
|
|
14
|
+
register_notifications
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def register_component_menus
|
|
18
|
+
[:read_blogs, :read_proposals].each do |name|
|
|
19
|
+
register_named(:menu, name) do |manifest|
|
|
20
|
+
manifest.settings do |settings|
|
|
21
|
+
settings.attribute :component_id, type: :integer
|
|
22
|
+
register_label_keys(settings, Decidim::Chatbot::MenuItemLabelKeys::READ_CONTENT)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
register_propose_proposals_menu
|
|
27
|
+
register_vote_on_proposal_menu
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def register_propose_proposals_menu
|
|
31
|
+
register_named(:menu, :propose_proposals) do |manifest|
|
|
32
|
+
manifest.settings do |settings|
|
|
33
|
+
settings.attribute :component_id, type: :integer
|
|
34
|
+
register_label_keys(settings, Decidim::Chatbot::MenuItemLabelKeys::PROPOSE_PROPOSALS)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def register_label_keys(settings, keys)
|
|
40
|
+
keys.each { |attr| settings.attribute attr, type: :string }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def register_vote_on_proposal_menu
|
|
44
|
+
register_named(:menu, :vote_on_proposal) do |manifest|
|
|
45
|
+
manifest.settings do |settings|
|
|
46
|
+
settings.attribute :component_id, type: :integer
|
|
47
|
+
settings.attribute :menu_button_label, type: :string
|
|
48
|
+
settings.attribute :menu_connector_label, type: :string
|
|
49
|
+
settings.attribute :skip_menu_button, type: :string
|
|
50
|
+
settings.attribute :vote_label, type: :string
|
|
51
|
+
settings.attribute :weight_1_label, type: :string
|
|
52
|
+
settings.attribute :weight_2_label, type: :string
|
|
53
|
+
settings.attribute :weight_3_label, type: :string
|
|
54
|
+
settings.attribute :abstention_label, type: :string
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def register_string_menus
|
|
60
|
+
register_named(:menu, :login) do |manifest|
|
|
61
|
+
manifest.settings do |settings|
|
|
62
|
+
settings.attribute :redirect_path, type: :string
|
|
63
|
+
settings.attribute :response_label, type: :string
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
register_typed(:menu, :exit, :response_label, :string)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def register_notifications
|
|
70
|
+
register_typed(:notification, :phase, :participatory_space_gid, :string)
|
|
71
|
+
register_typed(:notification, :manual, :template_id, :string)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def register_typed(scope, name, attribute, type)
|
|
75
|
+
register_named(scope, name) do |manifest|
|
|
76
|
+
manifest.settings { |settings| settings.attribute attribute, type: }
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def register_named(scope, name)
|
|
81
|
+
camel = name.to_s.camelize
|
|
82
|
+
ns = scope == :menu ? "MenuItems" : "Notifications"
|
|
83
|
+
Decidim::Chatbot.registry.register(scope, name) do |manifest|
|
|
84
|
+
manifest.form_class_name = "Decidim::Chatbot::Admin::#{ns}::#{camel}Form"
|
|
85
|
+
manifest.command_class_name = "Decidim::Chatbot::Admin::#{ns}::Update#{camel}"
|
|
86
|
+
yield(manifest)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails"
|
|
4
|
+
require "decidim/core"
|
|
5
|
+
require "decidim/admin"
|
|
6
|
+
require "decidim/toggle"
|
|
7
|
+
require "decidim/chatbot/settings_tab"
|
|
8
|
+
|
|
9
|
+
# Eager require: initializer runs early; app/services is not always autoload-ready when +Extension.register+ runs.
|
|
10
|
+
require File.join(
|
|
11
|
+
Decidim::Chatbot::ENGINE_ROOT,
|
|
12
|
+
"app/services/decidim/chatbot/chatbot_webhook_handler.rb"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
module Decidim
|
|
16
|
+
module Chatbot
|
|
17
|
+
class Engine < ::Rails::Engine
|
|
18
|
+
isolate_namespace Decidim::Chatbot
|
|
19
|
+
|
|
20
|
+
initializer "decidim_chatbot.registry" do
|
|
21
|
+
Decidim::Chatbot::DefaultManifests.register!
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
initializer "decidim_chatbot.webpacker.assets_path" do
|
|
25
|
+
packs = root.join("app/packs")
|
|
26
|
+
Decidim.register_assets_path File.expand_path(packs) if packs.directory?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
initializer "decidim_chatbot.organization_settings_tab",
|
|
30
|
+
after: "decidim_toggle.organization_settings_tabs" do
|
|
31
|
+
Decidim::Chatbot::SettingsTab.register!
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
initializer "decidim_chatbot.rest_full.ability" do
|
|
35
|
+
config.to_prepare do
|
|
36
|
+
Decidim::RestFull::Core::Ability.prepend(Decidim::Chatbot::RestFullAbility)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
initializer "decidim_chatbot.rest_full.extension",
|
|
41
|
+
before: "rest_full.scopes" do
|
|
42
|
+
Decidim::RestFull::Extension.register(:chatbot) do |ext|
|
|
43
|
+
ext.toggle_feature gem: "decidim-chatbot"
|
|
44
|
+
ext.controller_paths "chatbots", "chatbot_menu_items", "chatbot_users"
|
|
45
|
+
ext.oauth_scopes :whatsapp
|
|
46
|
+
ext.permissions(:whatsapp, "whatsapp.read", group: :whatsapp)
|
|
47
|
+
ext.open_api_definitions(
|
|
48
|
+
File.join(Decidim::Chatbot::ENGINE_ROOT, "lib/decidim/chatbot/test_definitions.rb")
|
|
49
|
+
)
|
|
50
|
+
ext.rswag_specs(
|
|
51
|
+
File.join(Decidim::Chatbot::ENGINE_ROOT, "spec/requests/decidim/api/rest_full/chatbot/**/*_spec.rb")
|
|
52
|
+
)
|
|
53
|
+
ext.webhook_event(
|
|
54
|
+
"chatbot.settings_updated.succeeded",
|
|
55
|
+
scope: :whatsapp,
|
|
56
|
+
payload_schema_ref: :chatbot,
|
|
57
|
+
schema_key: :wh_chatbot_settings_updated,
|
|
58
|
+
trigger: "Chatbot general settings saved",
|
|
59
|
+
example: lambda { |organization|
|
|
60
|
+
::Decidim::Api::RestFull::Chatbot::ChatbotWebhookSerializer.example_envelope(
|
|
61
|
+
organization,
|
|
62
|
+
event_name: "chatbot.settings_updated.succeeded"
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
)
|
|
66
|
+
ext.webhook_event(
|
|
67
|
+
"chatbot.menu_updated.succeeded",
|
|
68
|
+
scope: :whatsapp,
|
|
69
|
+
payload_schema_ref: :chatbot,
|
|
70
|
+
schema_key: :wh_chatbot_menu_updated,
|
|
71
|
+
trigger: "Chatbot menu item created, updated, destroyed, or reordered",
|
|
72
|
+
example: lambda { |organization|
|
|
73
|
+
::Decidim::Api::RestFull::Chatbot::ChatbotWebhookSerializer.example_envelope(
|
|
74
|
+
organization,
|
|
75
|
+
event_name: "chatbot.menu_updated.succeeded"
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
ext.webhooks(
|
|
80
|
+
Decidim::Chatbot::WebhookPublisher::SETTINGS_EVENT,
|
|
81
|
+
Decidim::Chatbot::WebhookPublisher::MENU_EVENT,
|
|
82
|
+
handler: Decidim::Chatbot::ChatbotWebhookHandler.method(:call)
|
|
83
|
+
)
|
|
84
|
+
ext.routes do
|
|
85
|
+
Decidim::RestFull::Routing.read_resources(
|
|
86
|
+
self, :chatbots, controller: "chatbot/chatbots", only: [:index, :show]
|
|
87
|
+
)
|
|
88
|
+
Decidim::RestFull::Routing.read_resources(
|
|
89
|
+
self, :chatbot_menu_items, controller: "chatbot/chatbot_menu_items", only: [:index, :show]
|
|
90
|
+
)
|
|
91
|
+
Decidim::RestFull::Routing.read_resources(
|
|
92
|
+
self, :chatbot_users, controller: "chatbot/chatbot_users", only: [:index, :show]
|
|
93
|
+
)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
initializer "decidim_chatbot.subscribe_step_activated" do
|
|
99
|
+
config.to_prepare do
|
|
100
|
+
Decidim::EventsManager.subscribe("decidim.events.participatory_process.step_activated") do |_name, data|
|
|
101
|
+
Decidim::Chatbot::Notifications::EnqueuePhase.call(data[:resource])
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
# One registered menu or notification item type.
|
|
6
|
+
class Manifest
|
|
7
|
+
include ActiveModel::Model
|
|
8
|
+
include Decidim::AttributeObject::Model
|
|
9
|
+
|
|
10
|
+
attribute :name, Symbol
|
|
11
|
+
attribute :form_class_name, String
|
|
12
|
+
attribute :command_class_name, String
|
|
13
|
+
|
|
14
|
+
validates :name, :form_class_name, :command_class_name, presence: true
|
|
15
|
+
|
|
16
|
+
def settings(&block)
|
|
17
|
+
@settings ||= Decidim::SettingsManifest.new
|
|
18
|
+
yield(@settings) if block
|
|
19
|
+
@settings
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def form_class
|
|
23
|
+
form_class_name.constantize
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def command_class
|
|
27
|
+
command_class_name.constantize
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
# Single source of truth for typed menu-item label setting keys.
|
|
6
|
+
module MenuItemLabelKeys
|
|
7
|
+
PROPOSE_PROPOSALS = [
|
|
8
|
+
:default_title_label, :body_label, :verification_label, :action_prompt_label,
|
|
9
|
+
:save_button_label, :success_label, :withdraw_button_label, :withdraw_success_label,
|
|
10
|
+
:creation_not_enabled_label,
|
|
11
|
+
:title_blank_label, :body_blank_label,
|
|
12
|
+
:title_must_start_with_caps_label, :body_must_start_with_caps_label,
|
|
13
|
+
:title_too_much_caps_label, :body_too_much_caps_label,
|
|
14
|
+
:title_too_short_label, :body_too_short_label,
|
|
15
|
+
:title_too_long_label, :body_too_long_label,
|
|
16
|
+
:title_too_many_marks_label, :body_too_many_marks_label
|
|
17
|
+
].freeze
|
|
18
|
+
|
|
19
|
+
READ_CONTENT = [
|
|
20
|
+
:menu_button_label,
|
|
21
|
+
:read_more_button_label,
|
|
22
|
+
:nothing_to_read_label
|
|
23
|
+
].freeze
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
# ContentBlockRegistry-shaped store with :menu and :notification scopes.
|
|
6
|
+
class Registry
|
|
7
|
+
class AlreadyRegistered < StandardError; end
|
|
8
|
+
|
|
9
|
+
def register(scope, name)
|
|
10
|
+
scope = scope.to_s
|
|
11
|
+
raise AlreadyRegistered, unique_message(scope, name) if exists?(scope, name)
|
|
12
|
+
|
|
13
|
+
manifest = Manifest.new(name:)
|
|
14
|
+
yield(manifest)
|
|
15
|
+
manifest.validate!
|
|
16
|
+
manifests[scope].push(manifest)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def for(scope)
|
|
20
|
+
manifests[scope.to_s]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def all
|
|
24
|
+
manifests
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def exists?(scope, name)
|
|
30
|
+
manifests[scope].any? { |manifest| manifest.name == name }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def unique_message(scope, name)
|
|
34
|
+
"Already registered :#{name} for scope :#{scope}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def manifests
|
|
38
|
+
@manifests ||= Hash.new { |hash, key| hash[key] = [] }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
# Grants CanCan :read when OAuth scope +whatsapp+ and permission +whatsapp.read+.
|
|
6
|
+
module RestFullAbility
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
def apply_permissions!(scopes)
|
|
10
|
+
super
|
|
11
|
+
perms_for_whatsapp if scopes.include?("whatsapp")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def perms_for_whatsapp
|
|
17
|
+
return unless permissions.include?("whatsapp.read")
|
|
18
|
+
|
|
19
|
+
can :read, Decidim::Chatbot::Chatbot
|
|
20
|
+
can :read, Decidim::Chatbot::Item
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Chatbot
|
|
5
|
+
class SettingsTab
|
|
6
|
+
def self.register!
|
|
7
|
+
Decidim::Toggle.settings_tabs :organization_settings do |tabs|
|
|
8
|
+
tabs.add_tab :decidim_chatbot,
|
|
9
|
+
I18n.t("decidim_toggle.system.#{Decidim::Chatbot::MODULE_NAME}.tab"),
|
|
10
|
+
form: Decidim::Chatbot::Admin::ConfigForm,
|
|
11
|
+
command: Decidim::Toggle::UpdateModuleConfigCommand,
|
|
12
|
+
module_name: Decidim::Chatbot::MODULE_NAME,
|
|
13
|
+
position: 25
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|