whatsapp_sdk 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codeql-analysis.yml +8 -6
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +0 -3
  5. data/CHANGELOG.md +9 -7
  6. data/Gemfile +0 -4
  7. data/Gemfile.lock +1 -20
  8. data/README.md +35 -55
  9. data/SECURITY.md +21 -0
  10. data/example.rb +23 -15
  11. data/lib/whatsapp_sdk/api/api_configuration.rb +2 -5
  12. data/lib/whatsapp_sdk/api/business_profile.rb +0 -12
  13. data/lib/whatsapp_sdk/api/client.rb +7 -43
  14. data/lib/whatsapp_sdk/api/medias.rb +8 -15
  15. data/lib/whatsapp_sdk/api/messages.rb +4 -81
  16. data/lib/whatsapp_sdk/api/phone_numbers.rb +0 -14
  17. data/lib/whatsapp_sdk/api/request.rb +0 -2
  18. data/lib/whatsapp_sdk/api/response.rb +1 -20
  19. data/lib/whatsapp_sdk/api/responses/business_profile_data_response.rb +11 -34
  20. data/lib/whatsapp_sdk/api/responses/data_response.rb +0 -9
  21. data/lib/whatsapp_sdk/api/responses/error_response.rb +1 -8
  22. data/lib/whatsapp_sdk/api/responses/generic_error_response.rb +8 -26
  23. data/lib/whatsapp_sdk/api/responses/media_data_response.rb +8 -26
  24. data/lib/whatsapp_sdk/api/responses/message_data_response.rb +4 -20
  25. data/lib/whatsapp_sdk/api/responses/message_error_response.rb +0 -1
  26. data/lib/whatsapp_sdk/api/responses/message_template_namespace_data_response.rb +3 -13
  27. data/lib/whatsapp_sdk/api/responses/phone_number_data_response.rb +19 -37
  28. data/lib/whatsapp_sdk/api/responses/phone_numbers_data_response.rb +2 -9
  29. data/lib/whatsapp_sdk/api/responses/read_message_data_response.rb +1 -6
  30. data/lib/whatsapp_sdk/api/responses/success_response.rb +1 -5
  31. data/lib/whatsapp_sdk/api/responses/template_data_response.rb +2 -7
  32. data/lib/whatsapp_sdk/api/responses/templates_data_response.rb +2 -9
  33. data/lib/whatsapp_sdk/api/templates.rb +3 -27
  34. data/lib/whatsapp_sdk/configuration.rb +2 -24
  35. data/lib/whatsapp_sdk/error.rb +0 -1
  36. data/lib/whatsapp_sdk/resource/address.rb +1 -30
  37. data/lib/whatsapp_sdk/resource/address_type.rb +3 -8
  38. data/lib/whatsapp_sdk/resource/business_profile.rb +0 -3
  39. data/lib/whatsapp_sdk/resource/button_parameter.rb +4 -20
  40. data/lib/whatsapp_sdk/resource/component.rb +12 -43
  41. data/lib/whatsapp_sdk/resource/contact.rb +1 -30
  42. data/lib/whatsapp_sdk/resource/contact_response.rb +1 -9
  43. data/lib/whatsapp_sdk/resource/currency.rb +0 -8
  44. data/lib/whatsapp_sdk/resource/date_time.rb +0 -6
  45. data/lib/whatsapp_sdk/resource/email.rb +1 -10
  46. data/lib/whatsapp_sdk/resource/errors.rb +1 -17
  47. data/lib/whatsapp_sdk/resource/interactive.rb +6 -27
  48. data/lib/whatsapp_sdk/resource/interactive_action.rb +10 -24
  49. data/lib/whatsapp_sdk/resource/interactive_action_reply_button.rb +5 -19
  50. data/lib/whatsapp_sdk/resource/interactive_action_section.rb +1 -11
  51. data/lib/whatsapp_sdk/resource/interactive_action_section_row.rb +0 -11
  52. data/lib/whatsapp_sdk/resource/interactive_body.rb +0 -10
  53. data/lib/whatsapp_sdk/resource/interactive_footer.rb +0 -10
  54. data/lib/whatsapp_sdk/resource/interactive_header.rb +25 -53
  55. data/lib/whatsapp_sdk/resource/location.rb +44 -0
  56. data/lib/whatsapp_sdk/resource/media.rb +10 -46
  57. data/lib/whatsapp_sdk/resource/media_types.rb +0 -3
  58. data/lib/whatsapp_sdk/resource/message.rb +0 -5
  59. data/lib/whatsapp_sdk/resource/name.rb +1 -28
  60. data/lib/whatsapp_sdk/resource/org.rb +1 -13
  61. data/lib/whatsapp_sdk/resource/parameter_object.rb +71 -74
  62. data/lib/whatsapp_sdk/resource/phone_number.rb +1 -13
  63. data/lib/whatsapp_sdk/resource/template.rb +23 -36
  64. data/lib/whatsapp_sdk/resource/url.rb +1 -10
  65. data/lib/whatsapp_sdk/version.rb +1 -2
  66. data/lib/whatsapp_sdk.rb +0 -4
  67. data/whatsapp_sdk.gemspec +0 -3
  68. metadata +5 -49
  69. data/sorbet/config +0 -6
  70. data/sorbet/rbi/annotations/faraday.rbi +0 -17
  71. data/sorbet/rbi/annotations/mocha.rbi +0 -34
  72. data/sorbet/rbi/annotations/rainbow.rbi +0 -269
  73. data/sorbet/rbi/gems/faraday-multipart@1.0.4.rbi +0 -270
  74. data/sorbet/rbi/gems/faraday-net_http@2.0.3.rbi +0 -182
  75. data/sorbet/rbi/gems/faraday@2.3.0.rbi +0 -2494
  76. data/sorbet/rbi/gems/method_source@1.0.0.rbi +0 -272
  77. data/sorbet/rbi/gems/minitest@5.16.1.rbi +0 -1459
  78. data/sorbet/rbi/gems/mocha@1.14.0.rbi +0 -60
  79. data/sorbet/rbi/gems/multipart-post@2.2.3.rbi +0 -239
  80. data/sorbet/rbi/gems/netrc@0.11.0.rbi +0 -150
  81. data/sorbet/rbi/gems/oj@3.13.14.rbi +0 -589
  82. data/sorbet/rbi/gems/zeitwerk@2.6.0.rbi +0 -867
  83. data/sorbet/rbi/todo.rbi +0 -8
  84. data/sorbet/shims/request.rbi +0 -10
  85. data/sorbet/tapioca/config.yml +0 -13
  86. data/sorbet/tapioca/require.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dea461d7f7167bb795397c8986d26ff9e03605d6a1efcbb38c070923b1eb5744
4
- data.tar.gz: b60104fec89e5fa1d138ace09c85eb491b6ea479aa0c054d4270e8c5ff49df3f
3
+ metadata.gz: c730759fac4bf2321be036813acb1708c92c9476fc4af1b330a81a249ef8f1d9
4
+ data.tar.gz: 71a10b4c8449b2e2e240ad25be6352e19cf91870c6caa68b84849bbf6129a997
5
5
  SHA512:
6
- metadata.gz: 2845e0fd596392cc00405cc575085459c7f67a7b69f2182c1968683221ae9b9be9da48627f7c0b24e72ba5f2f315318a055c70cc5bdd19bc04ff5cf5875327f3
7
- data.tar.gz: 457f735cd54a27226c01daf7e6bc62cb6ea14d9721b1a32567d24c1e361d80584aee793683bf0be2178fa65b8c59575bb96177c62c59f2e939c6607e52bb2daf
6
+ metadata.gz: 2b0b1e93dd3370eb032c7f07fa14a2fc0c6561f96c091e862fb11f8c1fb0d8d4bcd008a5ffcef0b7abcc46b73262e86e52e1ef68bceadd9dd01066ed18b122b5
7
+ data.tar.gz: 9e028ba82392db6092a4c9f7d831df4f7f5ce4912ee916938d8c88fbad86a4d8f2471577f6c04cfa0ed9311953843d00a4f0b7148142fdc04e8c2770a09d0f68
@@ -39,29 +39,31 @@ jobs:
39
39
  steps:
40
40
  - name: Checkout repository
41
41
  uses: actions/checkout@v3
42
+ with:
43
+ node-version: '20'
42
44
 
43
45
  # Initializes the CodeQL tools for scanning.
44
46
  - name: Initialize CodeQL
45
- uses: github/codeql-action/init@v2
47
+ uses: github/codeql-action/init@v3
46
48
  with:
47
49
  languages: ${{ matrix.language }}
48
50
  # If you wish to specify custom queries, you can do so here or in a config file.
49
51
  # By default, queries listed here will override any specified in a config file.
50
52
  # Prefix the list here with "+" to use these queries and those in the config file.
51
-
53
+
52
54
  # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
53
55
  # queries: security-extended,security-and-quality
54
56
 
55
-
57
+
56
58
  # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57
59
  # If this step fails, then you should remove it and run the build manually (see below)
58
60
  - name: Autobuild
59
- uses: github/codeql-action/autobuild@v2
61
+ uses: github/codeql-action/autobuild@v3
60
62
 
61
63
  # ℹ️ Command-line programs to run using the OS shell.
62
64
  # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
63
65
 
64
- # If the Autobuild fails above, remove it and uncomment the following three lines.
66
+ # If the Autobuild fails above, remove it and uncomment the following three lines.
65
67
  # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
66
68
 
67
69
  # - run: |
@@ -69,4 +71,4 @@ jobs:
69
71
  # ./location_of_script_within_repo/buildscript.sh
70
72
 
71
73
  - name: Perform CodeQL Analysis
72
- uses: github/codeql-action/analyze@v2
74
+ uses: github/codeql-action/analyze@v3
data/.gitignore CHANGED
@@ -24,3 +24,4 @@ REMOVE.rb
24
24
 
25
25
  .rvmrc
26
26
  .DS_Store
27
+ .aider*
data/.rubocop.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  require:
2
2
  - rubocop-minitest
3
3
  - rubocop-performance
4
- - rubocop-sorbet
5
4
 
6
5
  AllCops:
7
6
  NewCops: enable
@@ -53,6 +52,4 @@ Gemspec/RequiredRubyVersion:
53
52
  Minitest/MultipleAssertions:
54
53
  Enabled: false
55
54
 
56
- Style/AccessorGrouping: # disabled so that we can use sorbet signatures for each attr
57
- Enabled: false
58
55
 
data/CHANGELOG.md CHANGED
@@ -1,15 +1,17 @@
1
1
  # Unreleased
2
+ - Remove sorbet dependency @ignacio-chiazzo [148](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/148)
3
+ - Added the ability to specify the `filename` [via the document](https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages) API. @sahilas [#137](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/137)
2
4
 
3
5
  # v 0.12.1
4
- - Fix bug using client/api_versions @mgruner [#134](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/134)
6
+ - Fix bug using `client/api_versions` @mgruner [#134](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/134)
5
7
 
6
8
  # v 0.12.0
7
9
  - Added ability to specify logger @chahmedejaz [#129](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/129)
8
10
  - Allow download of unsupported media types @dvuckovic [#128](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/128)
9
11
  - Allow users to specify the API version. @conr [#126](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/126)
10
- - Use http multipart only when is needed. @ignacio-chiazzo [#123](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/123)
12
+ - Use HTTP multipart only when needed. @ignacio-chiazzo [#123](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/123)
11
13
  - Validate Vertical on BusinessProfile update API. @ignacio-chiazzo [#120](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/120)
12
- - Added ability to specify fields param in the busines profile API. @ignacio-chiazzo [#119](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/119)
14
+ - Added ability to specify fields param in the business profile API. @ignacio-chiazzo [#119](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/119)
13
15
 
14
16
  # v 0.11.0
15
17
  - Bumped API version to v19. @paulomcnally https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/116
@@ -68,7 +70,7 @@ Remove warnings [#41](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/
68
70
  Require Faraday [#40](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/40)
69
71
 
70
72
  # v 0.4.0
71
- - Make the gem stricly typed using Sorbet [#34](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/34), [#35](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/35), [#37](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/37)
73
+ - Make the gem strictly typed using Sorbet [#34](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/34), [#35](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/35), [#37](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/37)
72
74
  - Object IDs are Strings in development [#37](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/37)
73
75
 
74
76
  # v 0.3.2
@@ -82,12 +84,12 @@ Require Faraday [#40](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/
82
84
 
83
85
  # v 0.2.0
84
86
  - Added Media API
85
- - Added error and sucess responses
86
- - Added faraday-multiplart as part of the library
87
+ - Added error and successful responses
88
+ - Added faraday-multipart as part of the library
87
89
 
88
90
  # v 0.1.0
89
91
  - Added Message Template API.
90
- - Added Currency and Datetime resources.
92
+ - Added Currency and DateTime resources.
91
93
  - Added Media resource.
92
94
  - Added Component and ParameterObject resource.
93
95
  - Fixed bug in recipient_number in Messages API.
data/Gemfile CHANGED
@@ -10,16 +10,12 @@ group(:test) do
10
10
  gem('rubocop', require: false)
11
11
  gem('rubocop-minitest', require: false)
12
12
  gem('rubocop-performance', require: false)
13
- gem('rubocop-sorbet', require: false)
14
13
  gem('webmock')
15
14
  end
16
15
 
17
16
  group(:development) do
18
17
  gem('pry')
19
18
  gem('pry-nav')
20
- gem('sorbet')
21
- gem('spoom')
22
- gem('tapioca', require: false)
23
19
  end
24
20
 
25
21
  gemspec
data/Gemfile.lock CHANGED
@@ -1,10 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- whatsapp_sdk (0.12.1)
4
+ whatsapp_sdk (0.13.0)
5
5
  faraday (~> 2)
6
6
  faraday-multipart (~> 1)
7
- sorbet-runtime (~> 0.5)
8
7
  zeitwerk (~> 2)
9
8
 
10
9
  GEM
@@ -58,22 +57,8 @@ GEM
58
57
  rubocop-performance (1.14.2)
59
58
  rubocop (>= 1.7.0, < 2.0)
60
59
  rubocop-ast (>= 0.4.0)
61
- rubocop-sorbet (0.7.0)
62
- rubocop (>= 0.90.0)
63
60
  ruby-progressbar (1.11.0)
64
61
  ruby2_keywords (0.0.5)
65
- sorbet (0.5.10346)
66
- sorbet-static (= 0.5.10346)
67
- sorbet-runtime (0.5.10346)
68
- sorbet-static (0.5.10346-universal-darwin-19)
69
- sorbet-static (0.5.10346-universal-darwin-21)
70
- sorbet-static (0.5.10346-x86_64-linux)
71
- spoom (1.1.12)
72
- sorbet (>= 0.5.9204)
73
- sorbet-runtime (>= 0.5.9204)
74
- thor (>= 0.19.2)
75
- tapioca (0.0.1)
76
- thor (1.2.1)
77
62
  unicode-display_width (2.2.0)
78
63
  webmock (3.18.1)
79
64
  addressable (>= 2.8.0)
@@ -97,10 +82,6 @@ DEPENDENCIES
97
82
  rubocop
98
83
  rubocop-minitest
99
84
  rubocop-performance
100
- rubocop-sorbet
101
- sorbet
102
- spoom
103
- tapioca
104
85
  webmock
105
86
  whatsapp_sdk!
106
87
 
data/README.md CHANGED
@@ -333,6 +333,8 @@ messages_api.send_document(
333
333
  )
334
334
  ```
335
335
 
336
+ Note, you can specify the filename via file [`filename` argument](https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages).
337
+
336
338
  **Send a sticker message**
337
339
  It could use a link or a sticker_id.
338
340
 
@@ -369,41 +371,42 @@ WhatsApp message templates are specific message formats that businesses use to s
369
371
  currency = WhatsappSdk::Resource::Currency.new(code: "USD", amount: 1000, fallback_value: "1000")
370
372
  date_time = WhatsappSdk::Resource::DateTime.new(fallback_value: "2020-01-01T00:00:00Z")
371
373
  image = WhatsappSdk::Resource::Media.new(type: "image", link: "http(s)://URL")
374
+ location = WhatsappSdk::Resource::Location.new(
375
+ latitude: 25.779510, longitude: -80.338631, name: "miami store", address: "820 nw 87th ave, miami, fl"
376
+ )
372
377
 
373
- parameter_image = WhatsappSdk::Resource::ParameterObject.new(type: WhatsappSdk::Resource::ParameterObject::Type::Image, image: image)
374
- # You can also use a plain string as type e.g.
375
- # parameter_image = WhatsappSdk::Resource::ParameterObject.new(type: "image", image: image)
376
- parameter_text = WhatsappSdk::Resource::ParameterObject.new(type: WhatsappSdk::Resource::ParameterObject::Type::Text, text: "TEXT_STRING")
377
- parameter_currency = WhatsappSdk::Resource::ParameterObject.new(type: WhatsappSdk::Resource::ParameterObject::Type::Currency, currency: currency)
378
- parameter_date_time = WhatsappSdk::Resource::ParameterObject.new(type: WhatsappSdk::Resource::ParameterObject::Type::DateTime, date_time: date_time)
378
+ parameter_image = WhatsappSdk::Resource::ParameterObject.new(type: "image", image: image)
379
+ parameter_text = WhatsappSdk::Resource::ParameterObject.new(type: "text", text: "TEXT_STRING")
380
+ parameter_currency = WhatsappSdk::Resource::ParameterObject.new(type: "currency", currency: currency)
381
+ parameter_date_time = WhatsappSdk::Resource::ParameterObject.new(type: "date_time", date_time: date_time)
382
+ parameter_location = WhatsappSdk::Resource::ParameterObject.new(type: "location", location: location)
379
383
 
380
- header_component = WhatsappSdk::Resource::Component.new(
381
- type: WhatsappSdk::Resource::Component::Type::Header,
382
- parameters: [parameter_image]
383
- )
384
+ header_component = WhatsappSdk::Resource::Component.new(type: "header", parameters: [parameter_image])
384
385
 
385
386
  body_component = WhatsappSdk::Resource::Component.new(
386
- type: WhatsappSdk::Resource::Component::Type::Body,
387
+ type: "body",
387
388
  parameters: [parameter_text, parameter_currency, parameter_date_time]
388
389
  )
389
390
 
390
391
  button_component1 = WhatsappSdk::Resource::Component.new(
391
- type: WhatsappSdk::Resource::Component::Type::Button,
392
+ type: "button",
392
393
  index: 0,
393
- sub_type: WhatsappSdk::Resource::Component::Subtype::QuickReply,
394
+ sub_type: "quick_reply",
394
395
  parameters: [
395
- WhatsappSdk::Resource::ButtonParameter.new(type: WhatsappSdk::Resource::ButtonParameter::Type::Payload, payload: "PAYLOAD")
396
+ WhatsappSdk::Resource::ButtonParameter.new(type: "payload", payload: "PAYLOAD")
396
397
  ]
397
398
  )
398
399
 
399
400
  button_component2 = WhatsappSdk::Resource::Component.new(
400
- type: WhatsappSdk::Resource::Component::Type::Button,
401
+ type: "button",
401
402
  index: 1,
402
- sub_type: WhatsappSdk::Resource::Component::Subtype::QuickReply,
403
+ sub_type: "quick_reply",
403
404
  parameters: [
404
- WhatsappSdk::Resource::ButtonParameter.new(type: WhatsappSdk::Resource::ButtonParameter::Type::Payload, payload: "PAYLOAD")
405
+ WhatsappSdk::Resource::ButtonParameter.new(type: "payload", payload: "PAYLOAD")
405
406
  ]
406
407
  )
408
+
409
+ location_component = WhatsappSdk::Resource::Component.new(type: "header", parameters: [parameter_location])
407
410
  @messages_api.send_template(sender_id: 12_345, recipient_number: 12345678, name: "hello_world", language: "en_US", components_json: [component_1])
408
411
  ```
409
412
 
@@ -422,28 +425,14 @@ Visit the [Official API Documentation](https://developers.facebook.com/docs/what
422
425
  <summary>List Message's example</summary>
423
426
 
424
427
  ```ruby
425
- interactive_header = WhatsappSdk::Resource::InteractiveHeader.new(
426
- type: WhatsappSdk::Resource::InteractiveHeader::Type::Text,
427
- text: "I am the header!"
428
- )
429
-
430
- interactive_body = WhatsappSdk::Resource::InteractiveBody.new(
431
- text: "I am the body!"
432
- )
433
-
434
- interactive_footer = WhatsappSdk::Resource::InteractiveFooter.new(
435
- text: "I am the footer!"
436
- )
437
-
438
- interactive_action = WhatsappSdk::Resource::InteractiveAction.new(
439
- type: WhatsappSdk::Resource::InteractiveAction::Type::ListMessage
440
- )
428
+ interactive_header = WhatsappSdk::Resource::InteractiveHeader.new(type: "text", text: "I am the header!")
429
+ interactive_body = WhatsappSdk::Resource::InteractiveBody.new(text: "I am the body!")
430
+ interactive_footer = WhatsappSdk::Resource::InteractiveFooter.new(text: "I am the footer!")
431
+ interactive_action = WhatsappSdk::Resource::InteractiveAction.new(type: "list_message")
441
432
 
442
433
  interactive_action.button = "I am the button CTA"
443
434
 
444
- interactive_section_1 = WhatsappSdk::Resource::InteractiveActionSection.new(
445
- title: "I am the section 1"
446
- )
435
+ interactive_section_1 = WhatsappSdk::Resource::InteractiveActionSection.new(title: "I am the section 1")
447
436
  interactive_section_1_row_1 = WhatsappSdk::Resource::InteractiveActionSectionRow.new(
448
437
  title: "I am the row 1 title",
449
438
  id: "section_1_row_1",
@@ -453,7 +442,7 @@ interactive_section_1.add_row(interactive_section_1_row_1)
453
442
  interactive_action.add_section(interactive_section_1)
454
443
 
455
444
  interactive_list_messages = WhatsappSdk::Resource::Interactive.new(
456
- type: WhatsappSdk::Resource::Interactive::Type::ListMessage,
445
+ type: "list",
457
446
  header: interactive_header,
458
447
  body: interactive_body,
459
448
  footer: interactive_footer,
@@ -481,23 +470,11 @@ messages_api.send_interactive_list_messages(
481
470
  <summary>Reply Button's example</summary>
482
471
 
483
472
  ```ruby
484
- interactive_header = WhatsappSdk::Resource::InteractiveHeader.new(
485
- type: WhatsappSdk::Resource::InteractiveHeader::Type::Text,
486
- text: "I am the header!"
487
- )
488
-
489
- interactive_body = WhatsappSdk::Resource::InteractiveBody.new(
490
- text: "I am the body!"
491
- )
492
-
493
- interactive_footer = WhatsappSdk::Resource::InteractiveFooter.new(
494
- text: "I am the footer!"
495
- )
496
-
497
- interactive_action = WhatsappSdk::Resource::InteractiveAction.new(
498
- type: WhatsappSdk::Resource::InteractiveAction::Type::ReplyButton
499
- )
473
+ interactive_header = WhatsappSdk::Resource::InteractiveHeader.new(type: "text", text: "I am the header!")
474
+ interactive_body = WhatsappSdk::Resource::InteractiveBody.new(text: "I am the body!")
475
+ interactive_footer = WhatsappSdk::Resource::InteractiveFooter.new(text: "I am the footer!")
500
476
 
477
+ interactive_action = WhatsappSdk::Resource::InteractiveAction.new(type: "reply_button")
501
478
  interactive_reply_button_1 = WhatsappSdk::Resource::InteractiveActionReplyButton.new(
502
479
  title: "I am the reply button 1",
503
480
  id: "button_1"
@@ -511,7 +488,7 @@ interactive_reply_button_2 = WhatsappSdk::Resource::InteractiveActionReplyButton
511
488
  interactive_action.add_reply_button(interactive_reply_button_2)
512
489
 
513
490
  interactive_reply_buttons = WhatsappSdk::Resource::Interactive.new(
514
- type: WhatsappSdk::Resource::Interactive::Type::ReplyButton,
491
+ type: "reply_button",
515
492
  header: interactive_header,
516
493
  body: interactive_body,
517
494
  footer: interactive_footer,
@@ -548,7 +525,10 @@ Visit [the example file](/example.rb) with examples to call the API in a single
548
525
 
549
526
  ## Troubleshooting
550
527
 
551
- - If the API response is `success`, but the message is not delivered, ensure the device you're sending the message to is using a supported Whatsapp version. [Check documentation](https://developers.facebook.com/docs/whatsapp/cloud-api/support/troubleshooting#message-not-delivered). Try also replying a message to the number you are registered on your Whatsapp.
528
+ If you try to send a text message directly without a message template created and approved in your Meta control panel, you can't start a chat with other people. But if you receive a message before, it's possible to send a message.
529
+
530
+ If the API response is still `success`, but the message is not delivered:
531
+ - ensure the device you're sending the message to is using a supported Whatsapp version. [Check documentation](https://developers.facebook.com/docs/whatsapp/cloud-api/support/troubleshooting#message-not-delivered). Try also replying a message to the number you are registered on your Whatsapp.
552
532
  - Ensure your Meta App uses an API version greater than or equal to `v.14`.
553
533
  - Ensure that the Panel in the Facebook dashboard doesn't display any errors.
554
534
 
data/SECURITY.md ADDED
@@ -0,0 +1,21 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Use this section to tell people about which versions of your project are
6
+ currently being supported with security updates.
7
+
8
+ | Version | Supported |
9
+ | ------- | ------------------ |
10
+ | 5.1.x | :white_check_mark: |
11
+ | 5.0.x | :x: |
12
+ | 4.0.x | :white_check_mark: |
13
+ | < 4.0 | :x: |
14
+
15
+ ## Reporting a Vulnerability
16
+
17
+ Use this section to tell people how to report a vulnerability.
18
+
19
+ Tell them where to go, how often they can expect to get an update on a
20
+ reported vulnerability, what to expect if the vulnerability is accepted or
21
+ declined, etc.
data/example.rb CHANGED
@@ -134,10 +134,10 @@ puts "DELETE template by id: #{print_data_or_error(delete_template, delete_templ
134
134
 
135
135
  ############################## Business API ##############################
136
136
  business_profile = business_profile_api.details(SENDER_ID)
137
- puts "DELETE Business Profile by id: #{print_data_or_error(delete_template, business_profile.data&.id) }"
137
+ puts "DELETE Business Profile by id: #{print_data_or_error(delete_template, business_profile.data&.about) }"
138
138
 
139
139
  updated_bp = business_profile_api.update(phone_number_id: SENDER_ID, params: { about: "A very cool business" } )
140
- puts "UPDATE Business Profile by id: #{print_data_or_error(updated_bp, updated_bp.data&.id) }"
140
+ puts "UPDATE Business Profile by id: #{print_data_or_error(updated_bp, updated_bp.data&.success?) }"
141
141
 
142
142
  ############################## Phone Numbers API ##############################
143
143
  registered_number = phone_numbers_api.registered_number(SENDER_ID)
@@ -271,14 +271,16 @@ response_with_object = messages_api.send_template(sender_id: SENDER_ID, recipien
271
271
  name: "hello_world", language: "en_US", components: [])
272
272
  puts response_with_object
273
273
 
274
- # Send a template with components.Remember to create the template first.
274
+ # Send a template with components (Remember to create the template first).
275
275
  header_component = WhatsappSdk::Resource::Component.new(
276
- type: WhatsappSdk::Resource::Component::Type::Header
276
+ type: WhatsappSdk::Resource::Component::Type::HEADER
277
277
  )
278
-
279
278
  image = WhatsappSdk::Resource::Media.new(type: "image", link: "http(s)://URL", caption: "caption")
280
279
  document = WhatsappSdk::Resource::Media.new(type: "document", link: "http(s)://URL", filename: "txt.rb")
281
280
  video = WhatsappSdk::Resource::Media.new(type: "video", id: "123")
281
+ location = WhatsappSdk::Resource::Location.new(
282
+ latitude: 25.779510, longitude: -80.338631, name: "miami store", address: "820 nw 87th ave, miami, fl"
283
+ )
282
284
 
283
285
  parameter_image = WhatsappSdk::Resource::ParameterObject.new(
284
286
  type: "image",
@@ -300,14 +302,20 @@ parameter_text = WhatsappSdk::Resource::ParameterObject.new(
300
302
  text: "I am a text"
301
303
  )
302
304
 
305
+ parameter_location = WhatsappSdk::Resource::ParameterObject.new(
306
+ type: "location",
307
+ location: location
308
+ )
309
+
303
310
  header_component.add_parameter(parameter_text)
304
311
  header_component.add_parameter(parameter_image)
305
312
  header_component.add_parameter(parameter_video)
306
313
  header_component.add_parameter(parameter_document)
314
+ header_component.add_parameter(parameter_location)
307
315
  header_component.to_json
308
316
 
309
317
  body_component = WhatsappSdk::Resource::Component.new(
310
- type: WhatsappSdk::Resource::Component::Type::Body
318
+ type: WhatsappSdk::Resource::Component::Type::BODY
311
319
  )
312
320
  body_component.add_parameter(parameter_text)
313
321
  body_component.add_parameter(parameter_image)
@@ -316,18 +324,18 @@ body_component.add_parameter(parameter_document)
316
324
  body_component.to_json
317
325
 
318
326
  button_component_1 = WhatsappSdk::Resource::Component.new(
319
- type: WhatsappSdk::Resource::Component::Type::Button,
327
+ type: WhatsappSdk::Resource::Component::Type::BUTTON,
320
328
  index: 0,
321
- sub_type: WhatsappSdk::Resource::Component::Subtype::QuickReply,
322
- parameters: [WhatsappSdk::Resource::ButtonParameter.new(type: WhatsappSdk::Resource::ButtonParameter::Type::Payload,
329
+ sub_type: WhatsappSdk::Resource::Component::Subtype::QUICK_REPLY,
330
+ parameters: [WhatsappSdk::Resource::ButtonParameter.new(type: WhatsappSdk::Resource::ButtonParameter::Type::PAYLOAD,
323
331
  payload: "payload")]
324
332
  )
325
333
 
326
334
  button_component_2 = WhatsappSdk::Resource::Component.new(
327
- type: WhatsappSdk::Resource::Component::Type::Button,
335
+ type: WhatsappSdk::Resource::Component::Type::BUTTON,
328
336
  index: 1,
329
- sub_type: WhatsappSdk::Resource::Component::Subtype::QuickReply,
330
- parameters: [WhatsappSdk::Resource::ButtonParameter.new(type: WhatsappSdk::Resource::ButtonParameter::Type::Payload,
337
+ sub_type: WhatsappSdk::Resource::Component::Subtype::QUICK_REPLY,
338
+ parameters: [WhatsappSdk::Resource::ButtonParameter.new(type: WhatsappSdk::Resource::ButtonParameter::Type::PAYLOAD,
331
339
  payload: "payload")]
332
340
  )
333
341
 
@@ -353,7 +361,7 @@ puts response_with_json
353
361
  ######### SEND INTERACTIVE MESSAGES
354
362
  ## with reply buttons
355
363
  interactive_header = WhatsappSdk::Resource::InteractiveHeader.new(
356
- type: WhatsappSdk::Resource::InteractiveHeader::Type::Text,
364
+ type: WhatsappSdk::Resource::InteractiveHeader::Type::TEXT,
357
365
  text: "I'm the header!"
358
366
  )
359
367
 
@@ -366,7 +374,7 @@ interactive_footer = WhatsappSdk::Resource::InteractiveFooter.new(
366
374
  )
367
375
 
368
376
  interactive_action = WhatsappSdk::Resource::InteractiveAction.new(
369
- type: WhatsappSdk::Resource::InteractiveAction::Type::ReplyButton,
377
+ type: WhatsappSdk::Resource::InteractiveAction::Type::REPLY_BUTTON,
370
378
  )
371
379
 
372
380
  interactive_reply_button_1 = WhatsappSdk::Resource::InteractiveActionReplyButton.new(
@@ -382,7 +390,7 @@ interactive_reply_button_2 = WhatsappSdk::Resource::InteractiveActionReplyButton
382
390
  interactive_action.add_reply_button(interactive_reply_button_2)
383
391
 
384
392
  interactive_reply_buttons = WhatsappSdk::Resource::Interactive.new(
385
- type: WhatsappSdk::Resource::Interactive::Type::ReplyButton,
393
+ type: WhatsappSdk::Resource::Interactive::Type::REPLY_BUTTON,
386
394
  header: interactive_header,
387
395
  body: interactive_body,
388
396
  footer: interactive_footer,
@@ -1,13 +1,10 @@
1
- # typed: strict
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module WhatsappSdk
5
4
  module Api
6
5
  module ApiConfiguration
7
- extend T::Sig
8
-
9
- DEFAULT_API_VERSION = T.let("v19.0", String)
10
- API_URL = T.let("https://graph.facebook.com", String)
6
+ DEFAULT_API_VERSION = "v19.0"
7
+ API_URL = "https://graph.facebook.com"
11
8
  end
12
9
  end
13
10
  end
@@ -1,4 +1,3 @@
1
- # typed: strict
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require_relative "request"
@@ -11,12 +10,8 @@ module WhatsappSdk
11
10
  DEFAULT_FIELDS = 'about,address,description,email,profile_picture_url,websites,vertical'
12
11
 
13
12
  class InvalidVertical < StandardError
14
- extend T::Sig
15
-
16
- sig { returns(String) }
17
13
  attr_accessor :message
18
14
 
19
- sig { params(vertical: String).void }
20
15
  def initialize(vertical:)
21
16
  @message = "invalid vertical #{vertical}. See the supported types in the official documentation " \
22
17
  "https://developers.facebook.com/docs/whatsapp/cloud-api/reference/business-profiles"
@@ -28,7 +23,6 @@ module WhatsappSdk
28
23
  #
29
24
  # @param phone_number_id [Integer] Phone Number Id.
30
25
  # @return [Api::Response] Response object.
31
- sig { params(phone_number_id: Integer, fields: T.nilable(T::Array[String])).returns(Api::Response) }
32
26
  def details(phone_number_id, fields: nil)
33
27
  fields = if fields
34
28
  fields.join(',')
@@ -52,11 +46,6 @@ module WhatsappSdk
52
46
  # @param phone_number_id [Integer] Phone Number Id.
53
47
  # @param params [Hash] Params to update.
54
48
  # @return [Api::Response] Response object.
55
- sig do
56
- params(
57
- phone_number_id: Integer, params: T::Hash[T.untyped, T.untyped]
58
- ).returns(Api::Response)
59
- end
60
49
  def update(phone_number_id:, params:)
61
50
  # this is a required field
62
51
  params[:messaging_product] = 'whatsapp'
@@ -76,7 +65,6 @@ module WhatsappSdk
76
65
 
77
66
  private
78
67
 
79
- sig { params(params: T::Hash[T.untyped, T.untyped]).returns(T::Boolean) }
80
68
  def valid_vertical?(params)
81
69
  return true unless params[:vertical]
82
70
 
@@ -1,4 +1,3 @@
1
- # typed: strict
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require "faraday"
@@ -7,26 +6,13 @@ require "faraday/multipart"
7
6
  module WhatsappSdk
8
7
  module Api
9
8
  class Client
10
- extend T::Sig
11
-
12
- API_VERSIONS = T.let(
13
- [
14
- 'v19.0', 'v18.0', 'v17.0', 'v16.0', 'v15.0', 'v14.0', 'v13.0', 'v12.0',
15
- 'v11.0', 'v10.0', 'v9.0', 'v8.0', 'v7.0', 'v6.0', 'v5.0', 'v4.0', 'v3.3',
16
- 'v3.2', 'v3.1', 'v3.0', 'v2.12', 'v2.11', 'v2.10', 'v2.9', 'v2.8', 'v2.7',
17
- 'v2.6', 'v2.5', 'v2.4', 'v2.3', 'v2.2', 'v2.1'
18
- ].freeze,
19
- T::Array[String]
20
- )
9
+ API_VERSIONS = [
10
+ 'v19.0', 'v18.0', 'v17.0', 'v16.0', 'v15.0', 'v14.0', 'v13.0', 'v12.0',
11
+ 'v11.0', 'v10.0', 'v9.0', 'v8.0', 'v7.0', 'v6.0', 'v5.0', 'v4.0', 'v3.3',
12
+ 'v3.2', 'v3.1', 'v3.0', 'v2.12', 'v2.11', 'v2.10', 'v2.9', 'v2.8', 'v2.7',
13
+ 'v2.6', 'v2.5', 'v2.4', 'v2.3', 'v2.2', 'v2.1'
14
+ ].freeze
21
15
 
22
- sig do
23
- params(
24
- access_token: String,
25
- api_version: String,
26
- logger: T.nilable(T.any(Logger, T.class_of(Logger))),
27
- logger_options: Hash
28
- ).void
29
- end
30
16
  def initialize(
31
17
  access_token,
32
18
  api_version = ApiConfiguration::DEFAULT_API_VERSION,
@@ -41,20 +27,10 @@ module WhatsappSdk
41
27
  @api_version = api_version
42
28
  end
43
29
 
44
- sig do
45
- params(
46
- endpoint: String,
47
- full_url: T.nilable(String),
48
- http_method: String,
49
- params: T::Hash[T.untyped, T.untyped],
50
- headers: T::Hash[T.untyped, T.untyped],
51
- multipart: T::Boolean
52
- ).returns(T.nilable(T::Hash[T.untyped, T.untyped]))
53
- end
54
30
  def send_request(endpoint: "", full_url: nil, http_method: "post", params: {}, headers: {}, multipart: false)
55
31
  url = full_url || "#{ApiConfiguration::API_URL}/#{@api_version}/"
56
32
 
57
- faraday_request = T.unsafe(faraday(url: url, multipart: multipart))
33
+ faraday_request = faraday(url: url, multipart: multipart)
58
34
 
59
35
  response = faraday_request.public_send(http_method, endpoint, request_params(params, headers), headers)
60
36
 
@@ -63,10 +39,6 @@ module WhatsappSdk
63
39
  JSON.parse(response.body)
64
40
  end
65
41
 
66
- sig do
67
- params(url: String, content_type_header: String, file_path: T.nilable(String))
68
- .returns(Net::HTTPResponse)
69
- end
70
42
  def download_file(url:, content_type_header:, file_path: nil)
71
43
  uri = URI.parse(url)
72
44
  request = Net::HTTP::Get.new(uri)
@@ -85,19 +57,12 @@ module WhatsappSdk
85
57
 
86
58
  private
87
59
 
88
- sig do
89
- params(
90
- params: T::Hash[T.untyped, T.untyped],
91
- headers: T::Hash[T.untyped, T.untyped]
92
- ).returns(T.any(T::Hash[T.untyped, T.untyped], String))
93
- end
94
60
  def request_params(params, headers)
95
61
  return params.to_json if params.is_a?(Hash) && headers['Content-Type'] == 'application/json'
96
62
 
97
63
  params
98
64
  end
99
65
 
100
- sig { params(url: String, multipart: T::Boolean).returns(Faraday::Connection) }
101
66
  def faraday(url:, multipart: false)
102
67
  ::Faraday.new(url) do |client|
103
68
  client.request(:multipart) if multipart
@@ -108,7 +73,6 @@ module WhatsappSdk
108
73
  end
109
74
  end
110
75
 
111
- sig { params(api_version: String).void }
112
76
  def validate_api_version(api_version)
113
77
  raise ArgumentError, "Invalid API version: #{api_version}" unless API_VERSIONS.include?(api_version)
114
78
  end