postproxy-sdk 1.12.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +480 -9
- data/lib/postproxy/client.rb +72 -7
- data/lib/postproxy/constants.rb +37 -2
- data/lib/postproxy/errors.rb +15 -0
- data/lib/postproxy/resources/api_keys.rb +30 -0
- data/lib/postproxy/resources/chats.rb +30 -1
- data/lib/postproxy/resources/comments.rb +52 -4
- data/lib/postproxy/resources/google_business.rb +194 -0
- data/lib/postproxy/resources/messages.rb +43 -2
- data/lib/postproxy/resources/placements.rb +35 -0
- data/lib/postproxy/resources/posts.rb +86 -25
- data/lib/postproxy/resources/profile_groups.rb +8 -1
- data/lib/postproxy/resources/profiles.rb +131 -0
- data/lib/postproxy/resources/whatsapp.rb +278 -0
- data/lib/postproxy/resources/whatsapp_templates.rb +108 -0
- data/lib/postproxy/types.rb +508 -28
- data/lib/postproxy/version.rb +1 -1
- data/lib/postproxy/webhook_events.rb +90 -4
- metadata +9 -4
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require "erb"
|
|
2
|
+
|
|
3
|
+
module PostProxy
|
|
4
|
+
module Resources
|
|
5
|
+
# WhatsApp message templates, which live on the WhatsApp Business account
|
|
6
|
+
# (the profile). A template is addressed by its PostProxy id, Meta's id, or
|
|
7
|
+
# its name — pass `language` with a name that exists in several languages.
|
|
8
|
+
class WhatsAppTemplates
|
|
9
|
+
def initialize(client)
|
|
10
|
+
@client = client
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# `refresh: true` re-reads the templates from Meta first.
|
|
14
|
+
def list(profile_id, name: nil, language: nil, status: nil, refresh: nil, profile_group_id: nil)
|
|
15
|
+
params = {}
|
|
16
|
+
params[:name] = name if name
|
|
17
|
+
params[:language] = language if language
|
|
18
|
+
params[:status] = status if status
|
|
19
|
+
params[:refresh] = refresh unless refresh.nil?
|
|
20
|
+
|
|
21
|
+
result = @client.request(:get, path(profile_id),
|
|
22
|
+
params: params.empty? ? nil : params,
|
|
23
|
+
profile_group_id: profile_group_id
|
|
24
|
+
)
|
|
25
|
+
templates = (result[:data] || []).map { |t| WhatsAppTemplate.new(**t) }
|
|
26
|
+
ListResponse.new(data: templates)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def get(profile_id, id, language: nil, profile_group_id: nil)
|
|
30
|
+
result = @client.request(:get, path(profile_id, id),
|
|
31
|
+
params: language ? { language: language } : nil,
|
|
32
|
+
profile_group_id: profile_group_id
|
|
33
|
+
)
|
|
34
|
+
WhatsAppTemplate.new(**result)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Submitted to Meta for review; follow `status` via #get or the
|
|
38
|
+
# `message_template.status_updated` webhook. `category` is MARKETING,
|
|
39
|
+
# UTILITY or AUTHENTICATION; `components` are Meta's component objects
|
|
40
|
+
# (HEADER, BODY, FOOTER, BUTTONS). Pass `library_template_name` (and its
|
|
41
|
+
# inputs) instead of `components` to create from Meta's template library.
|
|
42
|
+
def create(profile_id, name:, category:, language:, parameter_format: nil, components: nil,
|
|
43
|
+
library_template_name: nil, library_template_body_inputs: nil, library_template_button_inputs: nil,
|
|
44
|
+
message_send_ttl_seconds: nil, profile_group_id: nil, idempotency_key: nil)
|
|
45
|
+
json_body = {
|
|
46
|
+
name: name,
|
|
47
|
+
category: category,
|
|
48
|
+
language: language,
|
|
49
|
+
parameter_format: parameter_format,
|
|
50
|
+
components: components,
|
|
51
|
+
library_template_name: library_template_name,
|
|
52
|
+
library_template_body_inputs: library_template_body_inputs,
|
|
53
|
+
library_template_button_inputs: library_template_button_inputs,
|
|
54
|
+
message_send_ttl_seconds: message_send_ttl_seconds
|
|
55
|
+
}.compact
|
|
56
|
+
|
|
57
|
+
result = @client.request(:post, path(profile_id),
|
|
58
|
+
json: json_body,
|
|
59
|
+
profile_group_id: profile_group_id,
|
|
60
|
+
idempotency_key: idempotency_key
|
|
61
|
+
)
|
|
62
|
+
WhatsAppTemplate.new(**result)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def update(profile_id, id, components: nil, message_send_ttl_seconds: nil, language: nil,
|
|
66
|
+
profile_group_id: nil, idempotency_key: nil)
|
|
67
|
+
json_body = { components: components, message_send_ttl_seconds: message_send_ttl_seconds }.compact
|
|
68
|
+
|
|
69
|
+
result = @client.request(:patch, path(profile_id, id),
|
|
70
|
+
params: language ? { language: language } : nil,
|
|
71
|
+
json: json_body,
|
|
72
|
+
profile_group_id: profile_group_id,
|
|
73
|
+
idempotency_key: idempotency_key
|
|
74
|
+
)
|
|
75
|
+
WhatsAppTemplate.new(**result)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Deleting by name without `language` removes every language of the
|
|
79
|
+
# template.
|
|
80
|
+
def delete(profile_id, id, language: nil, profile_group_id: nil, idempotency_key: nil)
|
|
81
|
+
@client.request(:delete, path(profile_id, id),
|
|
82
|
+
params: language ? { language: language } : nil,
|
|
83
|
+
profile_group_id: profile_group_id,
|
|
84
|
+
idempotency_key: idempotency_key
|
|
85
|
+
)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Meta's ready-made template library.
|
|
89
|
+
def library(profile_id, name: nil, language: nil, profile_group_id: nil)
|
|
90
|
+
params = {}
|
|
91
|
+
params[:name] = name if name
|
|
92
|
+
params[:language] = language if language
|
|
93
|
+
|
|
94
|
+
@client.request(:get, "#{path(profile_id)}/library",
|
|
95
|
+
params: params.empty? ? nil : params,
|
|
96
|
+
profile_group_id: profile_group_id
|
|
97
|
+
)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
private
|
|
101
|
+
|
|
102
|
+
def path(profile_id, id = nil)
|
|
103
|
+
base = "/profiles/#{profile_id}/templates"
|
|
104
|
+
id.nil? ? base : "#{base}/#{ERB::Util.url_encode(id.to_s)}"
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|