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.
Files changed (285) hide show
  1. checksums.yaml +7 -0
  2. data/.erb_lint.yml +2134 -0
  3. data/.github/workflows/website.yml +57 -0
  4. data/.gitignore +13 -0
  5. data/.gitlab-ci.yml +204 -0
  6. data/.node-version +1 -0
  7. data/.nvmrc +1 -0
  8. data/.rspec +2 -0
  9. data/.rubocop.yml +17 -0
  10. data/.ruby-version +1 -0
  11. data/.simplecov +36 -0
  12. data/CONTRIBUTING.md +54 -0
  13. data/Gemfile +50 -0
  14. data/Gemfile.lock +1013 -0
  15. data/LICENSE.md +661 -0
  16. data/README.md +62 -0
  17. data/Rakefile +54 -0
  18. data/app/commands/decidim/chatbot/admin/destroy_item.rb +25 -0
  19. data/app/commands/decidim/chatbot/admin/menu_items/update_exit.rb +12 -0
  20. data/app/commands/decidim/chatbot/admin/menu_items/update_login.rb +12 -0
  21. data/app/commands/decidim/chatbot/admin/menu_items/update_propose_proposals.rb +12 -0
  22. data/app/commands/decidim/chatbot/admin/menu_items/update_read_blogs.rb +12 -0
  23. data/app/commands/decidim/chatbot/admin/menu_items/update_read_proposals.rb +12 -0
  24. data/app/commands/decidim/chatbot/admin/menu_items/update_vote_on_proposal.rb +12 -0
  25. data/app/commands/decidim/chatbot/admin/notifications/update_manual.rb +12 -0
  26. data/app/commands/decidim/chatbot/admin/notifications/update_phase.rb +12 -0
  27. data/app/commands/decidim/chatbot/admin/persist_item.rb +47 -0
  28. data/app/commands/decidim/chatbot/admin/reorder_items.rb +51 -0
  29. data/app/commands/decidim/chatbot/admin/send_test_notification.rb +74 -0
  30. data/app/commands/decidim/chatbot/admin/unsubscribe_user.rb +35 -0
  31. data/app/commands/decidim/chatbot/admin/update_chatbot.rb +17 -0
  32. data/app/commands/decidim/chatbot/notifications/deliver.rb +30 -0
  33. data/app/commands/decidim/chatbot/notifications/enqueue_phase.rb +67 -0
  34. data/app/commands/decidim/chatbot/notifications/send.rb +115 -0
  35. data/app/commands/decidim/chatbot/whatsapp/create_from_phone.rb +95 -0
  36. data/app/commands/decidim/chatbot/whatsapp/sync_phone.rb +56 -0
  37. data/app/controllers/decidim/api/rest_full/chatbot/base_controller.rb +52 -0
  38. data/app/controllers/decidim/api/rest_full/chatbot/chatbot_menu_items_controller.rb +49 -0
  39. data/app/controllers/decidim/api/rest_full/chatbot/chatbot_users_controller.rb +46 -0
  40. data/app/controllers/decidim/api/rest_full/chatbot/chatbots_controller.rb +40 -0
  41. data/app/controllers/decidim/chatbot/admin/chatbot_edit.rb +85 -0
  42. data/app/controllers/decidim/chatbot/admin/chatbots/generals_controller.rb +43 -0
  43. data/app/controllers/decidim/chatbot/admin/chatbots/menu_items_controller.rb +32 -0
  44. data/app/controllers/decidim/chatbot/admin/chatbots/notifications_controller.rb +92 -0
  45. data/app/controllers/decidim/chatbot/admin/chatbots/users/filterable.rb +33 -0
  46. data/app/controllers/decidim/chatbot/admin/chatbots/users_controller.rb +53 -0
  47. data/app/controllers/decidim/chatbot/admin/chatbots/whatsapps_controller.rb +59 -0
  48. data/app/controllers/decidim/chatbot/admin/chatbots_controller.rb +20 -0
  49. data/app/controllers/decidim/chatbot/admin/items_crud.rb +183 -0
  50. data/app/forms/decidim/chatbot/admin/chatbot_form.rb +20 -0
  51. data/app/forms/decidim/chatbot/admin/config_form.rb +20 -0
  52. data/app/forms/decidim/chatbot/admin/menu_item_form.rb +80 -0
  53. data/app/forms/decidim/chatbot/admin/menu_items/component_id_form.rb +60 -0
  54. data/app/forms/decidim/chatbot/admin/menu_items/exit_form.rb +24 -0
  55. data/app/forms/decidim/chatbot/admin/menu_items/login_form.rb +35 -0
  56. data/app/forms/decidim/chatbot/admin/menu_items/propose_proposals_form.rb +23 -0
  57. data/app/forms/decidim/chatbot/admin/menu_items/propose_proposals_labels.rb +53 -0
  58. data/app/forms/decidim/chatbot/admin/menu_items/read_blogs_form.rb +23 -0
  59. data/app/forms/decidim/chatbot/admin/menu_items/read_content_labels.rb +51 -0
  60. data/app/forms/decidim/chatbot/admin/menu_items/read_proposals_form.rb +23 -0
  61. data/app/forms/decidim/chatbot/admin/menu_items/vote_on_proposal_form.rb +123 -0
  62. data/app/forms/decidim/chatbot/admin/notification_item_form.rb +111 -0
  63. data/app/forms/decidim/chatbot/admin/notifications/manual_form.rb +13 -0
  64. data/app/forms/decidim/chatbot/admin/notifications/phase_form.rb +79 -0
  65. data/app/forms/decidim/chatbot/admin/notifications/template_fields.rb +60 -0
  66. data/app/forms/decidim/chatbot/admin/notifications/test_form.rb +179 -0
  67. data/app/helpers/decidim/chatbot/admin/items_helper.rb +44 -0
  68. data/app/jobs/decidim/chatbot/chatbot_webhook_job.rb +59 -0
  69. data/app/jobs/decidim/chatbot/send_notification_job.rb +33 -0
  70. data/app/models/decidim/chatbot/chatbot.rb +47 -0
  71. data/app/models/decidim/chatbot/item.rb +99 -0
  72. data/app/packs/.keep +0 -0
  73. data/app/presenters/decidim/chatbot/admin_log/chatbot_presenter.rb +42 -0
  74. data/app/presenters/decidim/chatbot/admin_log/item_presenter.rb +32 -0
  75. data/app/queries/decidim/chatbot/admin/proposal_vote_mode.rb +41 -0
  76. data/app/queries/decidim/chatbot/whatsapp_users.rb +58 -0
  77. data/app/serializers/decidim/api/rest_full/chatbot/chatbot_menu_item_serializer.rb +113 -0
  78. data/app/serializers/decidim/api/rest_full/chatbot/chatbot_notification_serializer.rb +19 -0
  79. data/app/serializers/decidim/api/rest_full/chatbot/chatbot_serializer.rb +66 -0
  80. data/app/serializers/decidim/api/rest_full/chatbot/chatbot_user_identity_serializer.rb +23 -0
  81. data/app/serializers/decidim/api/rest_full/chatbot/chatbot_user_serializer.rb +28 -0
  82. data/app/serializers/decidim/api/rest_full/chatbot/chatbot_webhook_serializer.rb +21 -0
  83. data/app/services/decidim/chatbot/chatbot_webhook_handler.rb +40 -0
  84. data/app/services/decidim/chatbot/notifications/bindings.rb +87 -0
  85. data/app/services/decidim/chatbot/whatsapp/body_parameters.rb +29 -0
  86. data/app/services/decidim/chatbot/whatsapp/graph_client.rb +136 -0
  87. data/app/services/decidim/chatbot/whatsapp/status_mapper.rb +93 -0
  88. data/app/services/decidim/chatbot/whatsapp/template_manager_url.rb +35 -0
  89. data/app/views/decidim/chatbot/admin/chatbots/generals/_menu_preview.html.erb +49 -0
  90. data/app/views/decidim/chatbot/admin/chatbots/generals/edit.html.erb +79 -0
  91. data/app/views/decidim/chatbot/admin/chatbots/index.html.erb +50 -0
  92. data/app/views/decidim/chatbot/admin/chatbots/menu_items/_form.html.erb +2 -0
  93. data/app/views/decidim/chatbot/admin/chatbots/menu_items/edit.html.erb +2 -0
  94. data/app/views/decidim/chatbot/admin/chatbots/menu_items/index.html.erb +43 -0
  95. data/app/views/decidim/chatbot/admin/chatbots/menu_items/new.html.erb +12 -0
  96. data/app/views/decidim/chatbot/admin/chatbots/notifications/_form.html.erb +4 -0
  97. data/app/views/decidim/chatbot/admin/chatbots/notifications/_manual_fields.html.erb +8 -0
  98. data/app/views/decidim/chatbot/admin/chatbots/notifications/_phase_fields.html.erb +6 -0
  99. data/app/views/decidim/chatbot/admin/chatbots/notifications/edit.html.erb +3 -0
  100. data/app/views/decidim/chatbot/admin/chatbots/notifications/index.html.erb +40 -0
  101. data/app/views/decidim/chatbot/admin/chatbots/notifications/new.html.erb +11 -0
  102. data/app/views/decidim/chatbot/admin/chatbots/notifications/test.html.erb +35 -0
  103. data/app/views/decidim/chatbot/admin/chatbots/tabs/_whatsapp.html.erb +47 -0
  104. data/app/views/decidim/chatbot/admin/chatbots/users/_filters.html.erb +23 -0
  105. data/app/views/decidim/chatbot/admin/chatbots/users/index.html.erb +56 -0
  106. data/app/views/decidim/chatbot/admin/chatbots/whatsapps/show.html.erb +5 -0
  107. data/app/views/decidim/chatbot/admin/shared/_item_form.html.erb +64 -0
  108. data/app/views/decidim/chatbot/admin/shared/_row_actions.html.erb +28 -0
  109. data/app/views/decidim/chatbot/admin/shared/_tabs_menu.html.erb +13 -0
  110. data/app/views/decidim/chatbot/admin/shared/_type_fields.html.erb +2 -0
  111. data/app/views/decidim/chatbot/admin/shared/_type_picker.html.erb +15 -0
  112. data/app/views/decidim/chatbot/admin/shared/type_fields/_component_id.html.erb +9 -0
  113. data/app/views/decidim/chatbot/admin/shared/type_fields/_exit.html.erb +5 -0
  114. data/app/views/decidim/chatbot/admin/shared/type_fields/_login.html.erb +8 -0
  115. data/app/views/decidim/chatbot/admin/shared/type_fields/_manual.html.erb +16 -0
  116. data/app/views/decidim/chatbot/admin/shared/type_fields/_phase.html.erb +46 -0
  117. data/app/views/decidim/chatbot/admin/shared/type_fields/_propose_proposals.html.erb +10 -0
  118. data/app/views/decidim/chatbot/admin/shared/type_fields/_read_blogs.html.erb +16 -0
  119. data/app/views/decidim/chatbot/admin/shared/type_fields/_read_proposals.html.erb +16 -0
  120. data/app/views/decidim/chatbot/admin/shared/type_fields/_vote_on_proposal.html.erb +26 -0
  121. data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_abstention_label.html.erb +7 -0
  122. data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_vote_label.html.erb +7 -0
  123. data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_votes_closed_warning.html.erb +6 -0
  124. data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_weight_labels.html.erb +15 -0
  125. data/bin/check +13 -0
  126. data/bin/ci-setup +38 -0
  127. data/bin/gen-node-client +112 -0
  128. data/bin/gen-openapi +248 -0
  129. data/bin/i18n-tasks +27 -0
  130. data/bin/postversion +17 -0
  131. data/config/i18n-tasks.yml +38 -0
  132. data/config/locales/decidim_chatbot.en.yml +323 -0
  133. data/config/locales/decidim_chatbot.fr.yml +29 -0
  134. data/contrib/decidim-node-client/.gitignore +4 -0
  135. data/contrib/decidim-node-client/.npmignore +1 -0
  136. data/contrib/decidim-node-client/.openapi-generator/FILES +8 -0
  137. data/contrib/decidim-node-client/.openapi-generator/VERSION +1 -0
  138. data/contrib/decidim-node-client/.openapi-generator-ignore +13 -0
  139. data/contrib/decidim-node-client/.yarnrc.yml +5 -0
  140. data/contrib/decidim-node-client/README.md +37 -0
  141. data/contrib/decidim-node-client/api.ts +14193 -0
  142. data/contrib/decidim-node-client/base.ts +70 -0
  143. data/contrib/decidim-node-client/common.ts +185 -0
  144. data/contrib/decidim-node-client/configuration.ts +138 -0
  145. data/contrib/decidim-node-client/git_push.sh +57 -0
  146. data/contrib/decidim-node-client/index.ts +16 -0
  147. data/contrib/decidim-node-client/package.json +49 -0
  148. data/contrib/decidim-node-client/packup.config.ts +7 -0
  149. data/contrib/decidim-node-client/tsconfig.json +25 -0
  150. data/contrib/decidim-node-client/yarn.lock +2367 -0
  151. data/crowdin.yml +15 -0
  152. data/db/migrate/20260725120000_create_decidim_chatbot_chatbots.rb +20 -0
  153. data/db/migrate/20260822120000_create_decidim_chatbot_items.rb +20 -0
  154. data/db/migrate/20260824120000_add_menu_and_error_copy_to_decidim_chatbot_chatbots.rb +13 -0
  155. data/db/migrate/20260824140000_add_enabled_to_decidim_chatbot_items.rb +7 -0
  156. data/decidim-chatbot.gemspec +40 -0
  157. data/docker-compose.ci.yml +59 -0
  158. data/docker-compose.yml +47 -0
  159. data/lib/decidim/chatbot/admin_engine.rb +67 -0
  160. data/lib/decidim/chatbot/admin_menu.rb +41 -0
  161. data/lib/decidim/chatbot/default_manifests.rb +91 -0
  162. data/lib/decidim/chatbot/engine.rb +107 -0
  163. data/lib/decidim/chatbot/manifest.rb +31 -0
  164. data/lib/decidim/chatbot/menu_item_label_keys.rb +26 -0
  165. data/lib/decidim/chatbot/registry.rb +42 -0
  166. data/lib/decidim/chatbot/rest_full_ability.rb +24 -0
  167. data/lib/decidim/chatbot/settings_tab.rb +18 -0
  168. data/lib/decidim/chatbot/test_definitions.rb +352 -0
  169. data/lib/decidim/chatbot/variable_interpolator.rb +30 -0
  170. data/lib/decidim/chatbot/version.rb +21 -0
  171. data/lib/decidim/chatbot/webhook_publisher.rb +29 -0
  172. data/lib/decidim/chatbot.rb +41 -0
  173. data/lib/decidim-chatbot.rb +3 -0
  174. data/lib/tasks/chatbot.rake +64 -0
  175. data/openapi/openapi.json +37801 -0
  176. data/openapitools.json +7 -0
  177. data/package.json +22 -0
  178. data/prettier.config.js +15 -0
  179. data/spec/commands/decidim/chatbot/admin/destroy_item_spec.rb +24 -0
  180. data/spec/commands/decidim/chatbot/admin/persist_item_spec.rb +80 -0
  181. data/spec/commands/decidim/chatbot/admin/reorder_items_spec.rb +53 -0
  182. data/spec/commands/decidim/chatbot/admin/send_test_notification_spec.rb +105 -0
  183. data/spec/commands/decidim/chatbot/admin/unsubscribe_user_spec.rb +46 -0
  184. data/spec/commands/decidim/chatbot/admin/update_chatbot_spec.rb +56 -0
  185. data/spec/commands/decidim/chatbot/notifications/enqueue_phase_spec.rb +59 -0
  186. data/spec/commands/decidim/chatbot/notifications/send_spec.rb +101 -0
  187. data/spec/commands/decidim/chatbot/whatsapp/create_from_phone_spec.rb +122 -0
  188. data/spec/commands/decidim/chatbot/whatsapp/sync_phone_spec.rb +110 -0
  189. data/spec/controllers/decidim/chatbot/admin/chatbots_controller_spec.rb +25 -0
  190. data/spec/factories/chatbot.rb +44 -0
  191. data/spec/forms/decidim/chatbot/admin/chatbot_form_spec.rb +41 -0
  192. data/spec/forms/decidim/chatbot/admin/config_form_spec.rb +30 -0
  193. data/spec/forms/decidim/chatbot/admin/menu_item_form_spec.rb +49 -0
  194. data/spec/forms/decidim/chatbot/admin/menu_items/component_id_form_spec.rb +54 -0
  195. data/spec/forms/decidim/chatbot/admin/menu_items/component_id_forms_spec.rb +512 -0
  196. data/spec/forms/decidim/chatbot/admin/menu_items/exit_form_spec.rb +39 -0
  197. data/spec/forms/decidim/chatbot/admin/menu_items/login_form_spec.rb +101 -0
  198. data/spec/forms/decidim/chatbot/admin/menu_items/propose_proposals_form_prefill_spec.rb +26 -0
  199. data/spec/forms/decidim/chatbot/admin/menu_items/read_blogs_form_prefill_spec.rb +22 -0
  200. data/spec/forms/decidim/chatbot/admin/notifications/manual_form_spec.rb +130 -0
  201. data/spec/forms/decidim/chatbot/admin/notifications/phase_form_spec.rb +79 -0
  202. data/spec/forms/decidim/chatbot/admin/notifications/test_form_spec.rb +172 -0
  203. data/spec/jobs/decidim/chatbot/chatbot_webhook_job_spec.rb +47 -0
  204. data/spec/jobs/decidim/chatbot/send_notification_job_spec.rb +53 -0
  205. data/spec/lib/decidim/chatbot/engine_spec.rb +44 -0
  206. data/spec/lib/decidim/chatbot/registry_spec.rb +30 -0
  207. data/spec/lib/decidim/chatbot/settings_tab_spec.rb +21 -0
  208. data/spec/lib/decidim/chatbot/variable_interpolator_spec.rb +34 -0
  209. data/spec/lib/decidim/chatbot/whatsapp/status_mapper_spec.rb +64 -0
  210. data/spec/lib/decidim/chatbot_spec.rb +59 -0
  211. data/spec/models/decidim/chatbot/chatbot_spec.rb +23 -0
  212. data/spec/models/decidim/chatbot/item_spec.rb +88 -0
  213. data/spec/presenters/decidim/chatbot/admin_log/chatbot_presenter_spec.rb +64 -0
  214. data/spec/queries/decidim/chatbot/admin/proposal_vote_mode_spec.rb +74 -0
  215. data/spec/queries/decidim/chatbot/whatsapp_users_spec.rb +57 -0
  216. data/spec/requests/decidim/api/rest_full/chatbot/chatbot_menu_items_controller_spec.rb +344 -0
  217. data/spec/requests/decidim/api/rest_full/chatbot/chatbot_users_controller_spec.rb +140 -0
  218. data/spec/requests/decidim/api/rest_full/chatbot/chatbots_controller_spec.rb +195 -0
  219. data/spec/requests/decidim/chatbot/admin/chatbots/notifications_controller_spec.rb +44 -0
  220. data/spec/requests/decidim/chatbot/admin/tenant_isolation_spec.rb +133 -0
  221. data/spec/requests/decidim/chatbot/admin/unsubscribe_user_spec.rb +28 -0
  222. data/spec/serializers/decidim/api/rest_full/chatbot/chatbot_menu_item_serializer_spec.rb +321 -0
  223. data/spec/serializers/decidim/api/rest_full/chatbot/chatbot_serializer_spec.rb +49 -0
  224. data/spec/serializers/decidim/api/rest_full/chatbot/chatbot_user_serializer_spec.rb +40 -0
  225. data/spec/services/decidim/chatbot/chatbot_webhook_handler_spec.rb +43 -0
  226. data/spec/services/decidim/chatbot/notifications/bindings_spec.rb +86 -0
  227. data/spec/services/decidim/chatbot/whatsapp/body_parameters_spec.rb +22 -0
  228. data/spec/services/decidim/chatbot/whatsapp/graph_client_spec.rb +205 -0
  229. data/spec/services/decidim/chatbot/whatsapp/template_manager_url_spec.rb +33 -0
  230. data/spec/spec_helper.rb +33 -0
  231. data/spec/support/allow_all_hosts.rb +9 -0
  232. data/spec/support/chatbot_admin.rb +16 -0
  233. data/spec/support/decidim_factories.rb +7 -0
  234. data/spec/support/decidim_system_factories.rb +3 -0
  235. data/spec/support/devise.rb +5 -0
  236. data/spec/support/rack_test_system_driver.rb +43 -0
  237. data/spec/support/whatsapp_graph.rb +15 -0
  238. data/spec/swagger_helper.rb +47 -0
  239. data/spec/system/decidim/chatbot/admin/admin_can_send_manual_when_ready_spec.rb +35 -0
  240. data/spec/system/decidim/chatbot/admin/admin_configures_vote_on_proposal_menu_item_spec.rb +84 -0
  241. data/spec/system/decidim/chatbot/admin/admin_confirms_send_now_recipient_count_spec.rb +40 -0
  242. data/spec/system/decidim/chatbot/admin/admin_creates_menu_item_with_demo_field_spec.rb +65 -0
  243. data/spec/system/decidim/chatbot/admin/admin_creates_phase_and_manual_notifications_spec.rb +52 -0
  244. data/spec/system/decidim/chatbot/admin/admin_does_not_see_other_org_processes_in_phase_select_spec.rb +27 -0
  245. data/spec/system/decidim/chatbot/admin/admin_does_not_see_other_organization_chatbots_spec.rb +25 -0
  246. data/spec/system/decidim/chatbot/admin/admin_is_redirected_when_chatbot_is_disabled_spec.rb +28 -0
  247. data/spec/system/decidim/chatbot/admin/admin_lists_organization_chatbots_spec.rb +36 -0
  248. data/spec/system/decidim/chatbot/admin/admin_manual_notification_sends_with_nickname_spec.rb +68 -0
  249. data/spec/system/decidim/chatbot/admin/admin_navigates_chatbot_main_tabs_spec.rb +52 -0
  250. data/spec/system/decidim/chatbot/admin/admin_phase_notification_sends_on_step_change_spec.rb +79 -0
  251. data/spec/system/decidim/chatbot/admin/admin_picks_published_blog_component_spec.rb +205 -0
  252. data/spec/system/decidim/chatbot/admin/admin_picks_published_participatory_space_spec.rb +45 -0
  253. data/spec/system/decidim/chatbot/admin/admin_reorders_chatbot_menu_items_spec.rb +29 -0
  254. data/spec/system/decidim/chatbot/admin/admin_sees_disabled_menu_item_faded_on_the_table_spec.rb +23 -0
  255. data/spec/system/decidim/chatbot/admin/admin_sees_disabled_notification_item_faded_on_the_table_spec.rb +40 -0
  256. data/spec/system/decidim/chatbot/admin/admin_sees_notification_facts_and_frozen_template_name_spec.rb +71 -0
  257. data/spec/system/decidim/chatbot/admin/admin_sees_propose_proposals_defaults_prefilled_spec.rb +119 -0
  258. data/spec/system/decidim/chatbot/admin/admin_sees_type_specific_fields_spec.rb +89 -0
  259. data/spec/system/decidim/chatbot/admin/admin_sees_whatsapp_facts_and_can_sync_spec.rb +48 -0
  260. data/spec/system/decidim/chatbot/admin/admin_sees_whatsapp_template_edit_link_spec.rb +37 -0
  261. data/spec/system/decidim/chatbot/admin/admin_tests_notification_spec.rb +125 -0
  262. data/spec/system/decidim/chatbot/admin/admin_unchecks_enabled_on_a_menu_item_spec.rb +30 -0
  263. data/spec/system/decidim/chatbot/admin/admin_unsubscribes_whatsapp_user_from_chatbot_spec.rb +35 -0
  264. data/spec/system/decidim/chatbot/admin/admin_updates_welcome_message_from_general_tab_spec.rb +84 -0
  265. data/spec/system/decidim/chatbot/system/admin_updates_organization_chatbot_settings_spec.rb +33 -0
  266. data/spec/tasks/chatbot_create_spec.rb +99 -0
  267. data/spec/tasks/chatbot_sync_spec.rb +90 -0
  268. data/website/.node-version +1 -0
  269. data/website/.nvmrc +1 -0
  270. data/website/docs/developer/_category_.json +4 -0
  271. data/website/docs/developer/contribute.md +87 -0
  272. data/website/docs/index.md +42 -0
  273. data/website/docs/integrate/_category_.json +4 -0
  274. data/website/docs/integrate/index.md +214 -0
  275. data/website/docusaurus.config.ts +93 -0
  276. data/website/package.json +37 -0
  277. data/website/sidebars.ts +7 -0
  278. data/website/src/css/custom.css +37 -0
  279. data/website/static/api-docs.html +2218 -0
  280. data/website/static/img/logo.svg +1 -0
  281. data/website/static/openapi.json +37801 -0
  282. data/website/tsconfig.json +6 -0
  283. data/website/yarn.lock +9782 -0
  284. data/yarn.lock +1003 -0
  285. 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