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