direct7 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/VERSION +1 -1
- data/direct7-0.0.12.gem +0 -0
- data/direct7.gemspec +1 -1
- data/lib/direct7/whatsapp.rb +62 -27
- data/test/test.rb +70 -48
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8c128191bac6a5abb2d2dfed05e504a36df201d394d44fb05dde354bc4e3e16
|
4
|
+
data.tar.gz: 0bd62c9782fa39cceebc1110bd68b68dc000d37e0548c11788fc882c48b2c0b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34016259c47fa36daf4e3829897fb7a3a5cb38f1e4f82222d02d1eec093d36db4e10ec038276dfe238132b08bd62bb241eaf99def9fa020cebd038d9392f7f39
|
7
|
+
data.tar.gz: 75564fd228ff33d129220c29961e20fc9e963d760c918b0331fc002218fc66122ae1172221238c0cbdd8f98f09f0e3c7eb395d6dd35bcdb0efc8af4beccde941
|
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.13
|
data/direct7-0.0.12.gem
ADDED
Binary file
|
data/direct7.gemspec
CHANGED
@@ -4,7 +4,7 @@ require "direct7/version"
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "direct7"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.13"
|
8
8
|
spec.authors = ["Direct7 Networks"]
|
9
9
|
spec.email = ["support@d7networks.com"]
|
10
10
|
spec.summary = "Ruby SDK for Direct7 Platform REST API"
|
data/lib/direct7/whatsapp.rb
CHANGED
@@ -10,12 +10,7 @@ module Direct7
|
|
10
10
|
@log = Logger.new(STDOUT) # You can customize the log destination as needed
|
11
11
|
end
|
12
12
|
|
13
|
-
def send_whatsapp_freeform_message(originator, recipient, message_type,
|
14
|
-
last_name= nil, display_name= nil, phone= nil,
|
15
|
-
email= nil, url= nil, latitude= nil, longitude= nil,
|
16
|
-
location_name= nil, location_address= nil,
|
17
|
-
attachment_type= nil, attachment_url= nil,
|
18
|
-
attachment_caption= nil)
|
13
|
+
def send_whatsapp_freeform_message(originator, recipient, message_type, body=nil, first_name=nil, last_name=nil, formatted_name=nil, phones=nil, emails=nil, urls=nil, latitude=nil, longitude=nil, name=nil, address=nil, type=nil, url=nil, caption=nil)
|
19
14
|
message = {
|
20
15
|
'originator' => originator,
|
21
16
|
'recipients' => [{'recipient' => recipient}],
|
@@ -26,40 +21,44 @@ module Direct7
|
|
26
21
|
|
27
22
|
case message_type
|
28
23
|
when 'CONTACTS'
|
29
|
-
message['content']['
|
30
|
-
'
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
'
|
36
|
-
|
24
|
+
message['content']['contacts'] = [{
|
25
|
+
'name' => {
|
26
|
+
'first_name' => first_name,
|
27
|
+
'last_name' => last_name,
|
28
|
+
'formatted_name' => formatted_name,
|
29
|
+
},
|
30
|
+
'phones' => (phones.map { |phone| { 'phone' => phone } } if phones),
|
31
|
+
'emails' => (emails.map { |email| { 'email' => email } } if emails),
|
32
|
+
'urls' => (urls.map { |url| { 'url' => url } } if urls),
|
33
|
+
}]
|
37
34
|
when 'LOCATION'
|
38
35
|
message['content']['location'] = {
|
39
36
|
'latitude' => latitude,
|
40
37
|
'longitude' => longitude,
|
41
|
-
'name' =>
|
42
|
-
'address' =>
|
38
|
+
'name' => name,
|
39
|
+
'address' => address,
|
43
40
|
}
|
44
41
|
when 'ATTACHMENT'
|
45
42
|
message['content']['attachment'] = {
|
46
|
-
'
|
47
|
-
'
|
48
|
-
'
|
43
|
+
'type' => type,
|
44
|
+
'url' => url,
|
45
|
+
'caption' => caption,
|
49
46
|
}
|
50
47
|
when 'TEXT'
|
51
|
-
message['content']['
|
48
|
+
message['content']['text'] = {
|
49
|
+
'body' => body,
|
50
|
+
}
|
52
51
|
end
|
53
|
-
|
54
|
-
response = @client.post(@client.host, '/whatsapp/
|
52
|
+
|
53
|
+
response = @client.post(@client.host, '/whatsapp/v2/send', params: { 'messages' => [message] })
|
55
54
|
@log.info('Message sent successfully.')
|
56
55
|
response
|
57
56
|
end
|
58
57
|
|
59
58
|
def send_whatsapp_templated_message(originator, recipient, template_id,
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
body_parameter_values, media_type=nil, media_url=nil,
|
60
|
+
latitude=nil, longitude=nil, location_name=nil,
|
61
|
+
location_address=nil,lto_expiration_time_ms=nil, coupon_code=nil, quick_replies= nil, actions= nil, carousel_cards=nil)
|
63
62
|
message = {
|
64
63
|
'originator' => originator,
|
65
64
|
'recipients' => [{'recipient' => recipient}],
|
@@ -87,8 +86,44 @@ module Direct7
|
|
87
86
|
message['content']['template']['media'] = { 'media_type' => media_type, 'media_url' => media_url }
|
88
87
|
end
|
89
88
|
end
|
90
|
-
|
91
|
-
|
89
|
+
|
90
|
+
if lto_expiration_time_ms
|
91
|
+
message['content']['template']['limited_time_offer'] = {
|
92
|
+
'expiration_time_ms' => 'lto_expiration_time_ms',
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
if coupon_code
|
97
|
+
message['content']['template']['buttons'] = {
|
98
|
+
'coupon_code' => [
|
99
|
+
{
|
100
|
+
"index"=> 0,
|
101
|
+
"type"=> "copy_code",
|
102
|
+
"coupon_code"=> coupon_code
|
103
|
+
}
|
104
|
+
]
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
if quick_replies
|
109
|
+
message['content']['template']['buttons'] = {
|
110
|
+
'quick_replies' => actquick_repliesions,
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
if actions
|
115
|
+
message['content']['template']['buttons'] = {
|
116
|
+
'actions' => actions,
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
if carousel_cards
|
121
|
+
message['content']['template']['carousel'] = {
|
122
|
+
'cards' => carousel_cards,
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
response = @client.post(@client.host, '/whatsapp/v2/send', true, params: { 'messages' => [message] })
|
92
127
|
@log.info('Message sent successfully.')
|
93
128
|
response
|
94
129
|
end
|
data/test/test.rb
CHANGED
@@ -5,7 +5,7 @@ require_relative '../lib/direct7/client'
|
|
5
5
|
|
6
6
|
class TestSERVICES < Test::Unit::TestCase
|
7
7
|
def setup
|
8
|
-
@client = Direct7::Client.new('
|
8
|
+
@client = Direct7::Client.new('Your API Token')
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_send_message
|
@@ -13,54 +13,76 @@ class TestSERVICES < Test::Unit::TestCase
|
|
13
13
|
originator='SignOTP',
|
14
14
|
report_url='https://the_url_to_recieve_delivery_report.com',
|
15
15
|
schedule_time=nil,
|
16
|
-
{ recipients: ['+
|
16
|
+
{ recipients: ['+991999999XXXX'], content: 'Greetings from D7 API', unicode: false }
|
17
17
|
)
|
18
18
|
puts response1
|
19
|
-
|
20
|
-
|
19
|
+
response2 = @client.sms.get_status(request_id= '001a1a4e-0221-4cb7-a524-a2a5b337cbe8')
|
20
|
+
puts response2
|
21
|
+
end
|
22
|
+
def test_slack_send_message
|
23
|
+
response1 = @client.slack.send_slack_message(content="Greetings from D7 API", work_space_name="WorkSpaceName", channel_name="ChannelName", report_url="https://the_url_to_recieve_delivery_report.com" )
|
24
|
+
puts response1
|
25
|
+
response2 = @client.slack.get_status(request_id= '002599bf-e53d-46ad-b784-34f8fd5b6cf3')
|
26
|
+
puts response2
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_send_viber_message
|
30
|
+
response1 = @client.viber.send_viber_message(recipients=["+91999999XXXX"], content="Greetings from D7 API", label="PROMOTION", originator="SignOTP", call_back_url="https://the_url_to_recieve_delivery_report.com")
|
31
|
+
puts response1
|
32
|
+
response2 = @client.viber.get_status(request_id= 'd1319cc5-7183-43ff-8d98-0c18c5a62f1b')
|
33
|
+
puts response2
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_search_number_details
|
37
|
+
response = @client.number_lookup.search_number_details(recipients="+91999999XXXX")
|
38
|
+
puts response
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_send_otp
|
42
|
+
response = @client.verify.send_otp(originator="SignOTP", recipient="+91999999XXXX", content="Greetings from D7 API, your mobile verification code is: {}", data_coding="text", expiry=600)
|
43
|
+
puts response
|
44
|
+
response = @client.verify.resend_otp(otp_id="bb0e35ea-b094-40c6-9dda-06e37e801446")
|
45
|
+
puts response
|
46
|
+
response = @client.verify.verify_otp(otp_id="bb0e35ea-b094-40c6-9dda-06e37e801446", otp_code="022089")
|
47
|
+
puts response
|
48
|
+
response = @client.verify.get_status(otp_id="bb0e35ea-b094-40c6-9dda-06e37e801446")
|
49
|
+
puts response
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_send_whatsapp_templated_message
|
53
|
+
response = @client.whatsapp.send_whatsapp_templated_message(originator="919061525574", recipient="91999999XXXX",
|
54
|
+
template_id="marketing_media_image", body_parameter_values={"0": "Customer"}, media_type="image",
|
55
|
+
media_url="https://d7networks.com/static/resources/css/img/favicon.d27f70e6ebd0.png"
|
56
|
+
)
|
57
|
+
puts response
|
58
|
+
response = @client.whatsapp.send_whatsapp_freeform_message(
|
59
|
+
originator= "91906154XXXX",
|
60
|
+
recipient= "+91999999XXXX",
|
61
|
+
message_type="CONTACTS", first_name="Amal", last_name="Anu", formatted_name="Amal Anu", phones=["91906152XXXX"], emails = ["amal@gmail.com"]
|
62
|
+
)
|
63
|
+
response = @client.whatsapp.get_status(request_id="81eca535-8131-4866-be18-b3d933604069")
|
64
|
+
puts response
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_send_whatsapp_freeform_message_text
|
68
|
+
response = @client.whatsapp.send_whatsapp_freeform_message(
|
69
|
+
originator= "+XXXXXXXXXXXX",
|
70
|
+
recipient= "XXXXXXXXXXX",
|
71
|
+
message_type= "TEXT",
|
72
|
+
body= "Hi",
|
73
|
+
)
|
74
|
+
puts response
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_send_whatsapp_freeform_message_attachment
|
78
|
+
response = @client.whatsapp.send_whatsapp_freeform_message(
|
79
|
+
originator= "+XXXXXXXXXXXX",
|
80
|
+
recipient= "XXXXXXXXXXX",
|
81
|
+
message_type= "ATTACHMENT",
|
82
|
+
type= "image",
|
83
|
+
url= "https=//upload.wikimedia.org",
|
84
|
+
caption= "Tet"
|
85
|
+
)
|
86
|
+
puts response
|
21
87
|
end
|
22
|
-
# def test_slack_send_message
|
23
|
-
# response1 = @client.slack.send_slack_message(content="Greetings from D7 API", work_space_name="WorkSpaceName", channel_name="ChannelName", report_url="https://the_url_to_recieve_delivery_report.com" )
|
24
|
-
# puts response1
|
25
|
-
# response2 = @client.slack.get_status(request_id= '002599bf-e53d-46ad-b784-34f8fd5b6cf3')
|
26
|
-
# puts response2
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# def test_send_viber_message
|
30
|
-
# response1 = @client.viber.send_viber_message(recipients=["+91999999XXXX"], content="Greetings from D7 API", label="PROMOTION", originator="SignOTP", call_back_url="https://the_url_to_recieve_delivery_report.com")
|
31
|
-
# puts response1
|
32
|
-
# response2 = @client.viber.get_status(request_id= 'd1319cc5-7183-43ff-8d98-0c18c5a62f1b')
|
33
|
-
# puts response2
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
# def test_search_number_details
|
37
|
-
# response = @client.number_lookup.search_number_details(recipients="+91999999XXXX")
|
38
|
-
# puts response
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
# def test_send_otp
|
42
|
-
# response = @client.verify.send_otp(originator="SignOTP", recipient="+91999999XXXX", content="Greetings from D7 API, your mobile verification code is: {}", data_coding="text", expiry=600)
|
43
|
-
# puts response
|
44
|
-
# response = @client.verify.resend_otp(otp_id="bb0e35ea-b094-40c6-9dda-06e37e801446")
|
45
|
-
# puts response
|
46
|
-
# response = @client.verify.verify_otp(otp_id="bb0e35ea-b094-40c6-9dda-06e37e801446", otp_code="022089")
|
47
|
-
# puts response
|
48
|
-
# response = @client.verify.get_status(otp_id="bb0e35ea-b094-40c6-9dda-06e37e801446")
|
49
|
-
# puts response
|
50
|
-
# end
|
51
|
-
#
|
52
|
-
# def test_send_whatsapp_templated_message
|
53
|
-
# response = @client.whatsapp.send_whatsapp_templated_message(originator="919061525574", recipient="91999999XXXX",
|
54
|
-
# template_id="marketing_media_image", body_parameter_values={"0": "Customer"}, media_type="image",
|
55
|
-
# media_url="https://d7networks.com/static/resources/css/img/favicon.d27f70e6ebd0.png"
|
56
|
-
# )
|
57
|
-
# puts response
|
58
|
-
# response = @client.whatsapp.send_whatsapp_freeform_message(
|
59
|
-
# originator= "91906154XXXX",
|
60
|
-
# recipient= "+91999999XXXX",
|
61
|
-
# message_type="CONTACTS", first_name="Amal", last_name="Anu", display_name="Amal Anu", phone="91906152XXXX", email = "amal@gmail.com"
|
62
|
-
# )
|
63
|
-
# response = @client.whatsapp.get_status(request_id="81eca535-8131-4866-be18-b3d933604069")
|
64
|
-
# puts response
|
65
|
-
# end
|
66
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: direct7
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Direct7 Networks
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- VERSION
|
129
129
|
- direct7-0.0.10.gem
|
130
130
|
- direct7-0.0.11.gem
|
131
|
+
- direct7-0.0.12.gem
|
131
132
|
- direct7.gemspec
|
132
133
|
- doc/Direct7.html
|
133
134
|
- doc/Direct7/AuthenticationError.html
|