Skip to content

Commit 5a4d5f1

Browse files
author
Artur Khabibullin
authored
Merge pull request #29 from superstas/add_conversations
2 parents 479da98 + 248dce3 commit 5a4d5f1

30 files changed

+1082
-34
lines changed

examples/conversation.rb

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env ruby
2+
3+
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib/')
4+
require 'messagebird'
5+
6+
# ACCESS_KEY = ''
7+
8+
unless defined?(ACCESS_KEY)
9+
puts 'You need to set an ACCESS_KEY constant in this file'
10+
exit 1
11+
end
12+
13+
begin
14+
# Create a MessageBird client with the specified ACCESS_KEY.
15+
client = MessageBird::Client.new(ACCESS_KEY)
16+
17+
# Start a conversation
18+
conversation = client.conversation('conversationId')
19+
20+
# Print the object information.
21+
puts
22+
puts "The following information was returned as a conversation object:"
23+
puts " id : #{conversation.id}"
24+
puts " status : #{conversation.status}"
25+
puts " createdDatetime : #{conversation.createdDatetime}"
26+
puts " updatedDatetime : #{conversation.updatedDatetime}"
27+
puts " lastReceivedDateklme : #{conversation.lastReceivedDatetime}"
28+
puts " lastUsedChannelId : #{conversation.lastUsedChannelId}"
29+
30+
puts " Contact :"
31+
puts " id : #{conversation.contact.id}"
32+
puts " href : #{conversation.contact.href}"
33+
puts " msisdn : #{conversation.contact.msisdn}"
34+
puts " firstName : #{conversation.contact.firstName}"
35+
puts " lastName : #{conversation.contact.lastName}"
36+
puts " custom1 : #{conversation.contact.customDetails.custom1}"
37+
puts " custom2 : #{conversation.contact.customDetails.custom2}"
38+
puts " custom3 : #{conversation.contact.customDetails.custom3}"
39+
puts " custom4 : #{conversation.contact.customDetails.custom4}"
40+
puts " createdDatetime : #{conversation.contact.createdDatetime}"
41+
puts " updatedDatetime : #{conversation.contact.updatedDatetime}"
42+
43+
puts " Channels :"
44+
conversation.channels.each do |channel|
45+
puts " id : #{channel.id}"
46+
puts " name : #{channel.name}"
47+
puts " platformId : #{channel.platformId}"
48+
puts " createdDatetime : #{channel.createdDatetime}"
49+
puts " updatedDatetime : #{channel.updatedDatetime}"
50+
puts
51+
end
52+
53+
puts " Messages :"
54+
puts " href : #{conversation.messages.href}"
55+
puts " totalCount : #{conversation.messages.totalCount}"
56+
57+
rescue MessageBird::ErrorException => ex
58+
puts
59+
puts 'An error occured while creating a conversation:'
60+
puts
61+
62+
ex.errors.each do |error|
63+
puts " code : #{error.code}"
64+
puts " description : #{error.description}"
65+
puts " parameter : #{error.parameter}"
66+
puts
67+
end
68+
end

examples/conversation_list.rb

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env ruby
2+
3+
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib/')
4+
require 'messagebird'
5+
6+
# ACCESS_KEY = ''
7+
8+
unless defined?(ACCESS_KEY)
9+
puts 'You need to set an ACCESS_KEY constant in this file'
10+
exit 1
11+
end
12+
13+
begin
14+
# Create a MessageBird client with the specified ACCESS_KEY.
15+
client = MessageBird::Client.new(ACCESS_KEY)
16+
17+
# Fetch the Conversation list
18+
offset = 0
19+
limit = 10
20+
conversations = client.conversation_list(limit, offset)
21+
22+
# Print the object information.
23+
puts "The following information was returned as a Conversation list:"
24+
puts
25+
puts " count : #{conversations.count}"
26+
puts " limit : #{conversations.limit}"
27+
puts " offset : #{conversations.offset}"
28+
puts " totalCount : #{conversations.totalCount}"
29+
puts " links : #{conversations.links}"
30+
puts
31+
conversations.items.each do |conversation|
32+
puts "Conversation:"
33+
puts " id : #{conversation.id}"
34+
puts " status : #{conversation.status}"
35+
puts " createdDatetime : #{conversation.createdDatetime}"
36+
puts " updatedDatetime : #{conversation.updatedDatetime}"
37+
puts " lastReceivedDateklme : #{conversation.lastReceivedDatetime}"
38+
puts " lastUsedChannelId : #{conversation.lastUsedChannelId}"
39+
40+
puts " Contact :"
41+
puts " id : #{conversation.contact.id}"
42+
puts " href : #{conversation.contact.href}"
43+
puts " msisdn : #{conversation.contact.msisdn}"
44+
puts " firstName : #{conversation.contact.firstName}"
45+
puts " lastName : #{conversation.contact.lastName}"
46+
puts " custom1 : #{conversation.contact.customDetails.custom1}"
47+
puts " custom2 : #{conversation.contact.customDetails.custom2}"
48+
puts " custom3 : #{conversation.contact.customDetails.custom3}"
49+
puts " custom4 : #{conversation.contact.customDetails.custom4}"
50+
puts " createdDatetime : #{conversation.contact.createdDatetime}"
51+
puts " updatedDatetime : #{conversation.contact.updatedDatetime}"
52+
53+
puts " Channels :"
54+
conversation.channels.each do |channel|
55+
puts " id : #{channel.id}"
56+
puts " name : #{channel.name}"
57+
puts " platformId : #{channel.platformId}"
58+
puts " createdDatetime : #{channel.createdDatetime}"
59+
puts " updatedDatetime : #{channel.updatedDatetime}"
60+
puts
61+
end
62+
63+
puts " Messages :"
64+
puts " href : #{conversation.messages.href}"
65+
puts " totalCount : #{conversation.messages.totalCount}"
66+
puts
67+
end
68+
69+
rescue MessageBird::ErrorException => ex
70+
puts
71+
puts 'An error occured while creating a conversation:'
72+
puts
73+
74+
ex.errors.each do |error|
75+
puts " code : #{error.code}"
76+
puts " description : #{error.description}"
77+
puts " parameter : #{error.parameter}"
78+
puts
79+
end
80+
end

examples/conversation_message.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env ruby
2+
3+
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib/')
4+
require 'messagebird'
5+
6+
# ACCESS_KEY = ''
7+
8+
unless defined?(ACCESS_KEY)
9+
puts 'You need to set an ACCESS_KEY constant in this file'
10+
exit 1
11+
end
12+
13+
begin
14+
# Create a MessageBird client with the specified ACCESS_KEY.
15+
client = MessageBird::Client.new(ACCESS_KEY)
16+
17+
# Fetch a message
18+
msg = client.conversation_message('00000000000000000000000000000000')
19+
20+
# Print the object information.
21+
puts <<EOF
22+
The following information was returned as a Message object:
23+
id : #{msg.id}
24+
conversationId : #{msg.conversationId}
25+
channelId : #{msg.channelId}
26+
direction : #{msg.direction}
27+
type : #{msg.type}
28+
status : #{msg.status}
29+
content : #{msg.content}
30+
createdDatetime : #{msg.createdDatetime}
31+
updatedDatetime : #{msg.updatedDatetime}
32+
EOF
33+
34+
rescue MessageBird::ErrorException => ex
35+
puts
36+
puts 'An error occured while creating a conversation:'
37+
puts
38+
39+
ex.errors.each do |error|
40+
puts " code : #{error.code}"
41+
puts " description : #{error.description}"
42+
puts " parameter : #{error.parameter}"
43+
puts
44+
end
45+
end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env ruby
2+
3+
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib/')
4+
require 'messagebird'
5+
6+
# ACCESS_KEY = ''
7+
8+
unless defined?(ACCESS_KEY)
9+
puts 'You need to set an ACCESS_KEY constant in this file'
10+
exit 1
11+
end
12+
13+
begin
14+
# Create a MessageBird client with the specified ACCESS_KEY.
15+
client = MessageBird::Client.new(ACCESS_KEY)
16+
17+
# Fetch the messages list
18+
offset = 0
19+
limit = 10
20+
list = client.conversation_messages_list('00000000000000000000000000000000', limit, offset)
21+
22+
# Print the object information.
23+
#
24+
puts "The following information was returned as a messages list:"
25+
puts
26+
puts " count : #{list.count}"
27+
puts " limit : #{list.limit}"
28+
puts " offset : #{list.offset}"
29+
puts " totalCount : #{list.totalCount}"
30+
puts " links : #{list.links}"
31+
puts
32+
33+
list.items.each do |msg|
34+
puts "Message:"
35+
puts " id : #{msg.id}"
36+
puts " conversationId : #{msg.conversationId}"
37+
puts " channelId : #{msg.channelId}"
38+
puts " direction : #{msg.direction}"
39+
puts " type : #{msg.type}"
40+
puts " status : #{msg.status}"
41+
puts " content : #{msg.content}"
42+
puts " createdDatetime : #{msg.createdDatetime}"
43+
puts " updatedDatetime : #{msg.updatedDatetime}"
44+
puts
45+
end
46+
47+
rescue MessageBird::ErrorException => ex
48+
puts
49+
puts 'An error occured while creating a conversation:'
50+
puts
51+
52+
ex.errors.each do |error|
53+
puts " code : #{error.code}"
54+
puts " description : #{error.description}"
55+
puts " parameter : #{error.parameter}"
56+
puts
57+
end
58+
end

examples/conversation_reply.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env ruby
2+
3+
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib/')
4+
require 'messagebird'
5+
6+
# ACCESS_KEY = ''
7+
8+
unless defined?(ACCESS_KEY)
9+
puts 'You need to set an ACCESS_KEY constant in this file'
10+
exit 1
11+
end
12+
13+
begin
14+
# Create a MessageBird client with the specified ACCESS_KEY.
15+
client = MessageBird::Client.new(ACCESS_KEY)
16+
17+
# Reply to a conversation
18+
msg = client.conversation_reply('00000000000000000000000000000000', :type => 'text', :content => { :text => "Hi there" })
19+
20+
# Print the object information.
21+
puts <<EOF
22+
The following information was returned as a Message object:
23+
id : #{msg.id}
24+
conversationId : #{msg.conversationId}
25+
channelId : #{msg.channelId}
26+
direction : #{msg.direction}
27+
type : #{msg.type}
28+
status : #{msg.status}
29+
content : #{msg.content}
30+
createdDatetime : #{msg.createdDatetime}
31+
updatedDatetime : #{msg.updatedDatetime}
32+
EOF
33+
34+
rescue MessageBird::ErrorException => ex
35+
puts
36+
puts 'An error occured while updating a conversation:'
37+
puts
38+
39+
ex.errors.each do |error|
40+
puts " code : #{error.code}"
41+
puts " description : #{error.description}"
42+
puts " parameter : #{error.parameter}"
43+
puts
44+
end
45+
end

examples/conversation_update.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env ruby
2+
3+
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib/')
4+
require 'messagebird'
5+
6+
# ACCESS_KEY = ''
7+
8+
unless defined?(ACCESS_KEY)
9+
puts 'You need to set an ACCESS_KEY constant in this file'
10+
exit 1
11+
end
12+
13+
begin
14+
# Create a MessageBird client with the specified ACCESS_KEY.
15+
client = MessageBird::Client.new(ACCESS_KEY)
16+
17+
# Update a conversation
18+
conversation = client.conversation_update('57b96dbe0fda40f0a814f5e3268c30a9', MessageBird::Conversation::CONVERSATION_STATUS_ACTIVE)
19+
20+
# Print the object information.
21+
puts <<EOF
22+
The following information was returned as an updated conversation object:
23+
id : #{conversation.id}
24+
status : #{conversation.status}
25+
contactId : #{conversation.contactId}
26+
createdDatetime : #{conversation.createdDatetime}
27+
updatedDatetime : #{conversation.updatedDatetime}
28+
lastReceivedDateklme : #{conversation.lastReceivedDatetime}
29+
lastUsedChannelId : #{conversation.lastUsedChannelId}
30+
Messages :
31+
href : #{conversation.messages.href}
32+
totalCount : #{conversation.messages.totalCount}
33+
EOF
34+
35+
rescue MessageBird::ErrorException => ex
36+
puts
37+
puts 'An error occured while updating a conversation:'
38+
puts
39+
40+
ex.errors.each do |error|
41+
puts " code : #{error.code}"
42+
puts " description : #{error.description}"
43+
puts " parameter : #{error.parameter}"
44+
puts
45+
end
46+
end

examples/conversation_webhook.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env ruby
2+
3+
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib/')
4+
require 'messagebird'
5+
6+
# ACCESS_KEY = ''
7+
8+
unless defined?(ACCESS_KEY)
9+
puts 'You need to set an ACCESS_KEY constant in this file'
10+
exit 1
11+
end
12+
13+
begin
14+
# Create a MessageBird client with the specified ACCESS_KEY.
15+
client = MessageBird::Client.new(ACCESS_KEY)
16+
17+
# Get a webhook
18+
webhook = client.conversation_webhook('00000000000000000000000000000000')
19+
20+
# Print the object information.
21+
puts "The following information was returned as a Webhook object"
22+
puts " id : #{webhook.id}"
23+
puts " events : #{webhook.events}"
24+
puts " channelId : #{webhook.channelId}"
25+
puts " url : #{webhook.url}"
26+
puts " status : #{webhook.status}"
27+
puts " createdDatetime : #{webhook.createdDatetime}"
28+
puts " updatedDatetime : #{webhook.updatedDatetime}"
29+
30+
rescue MessageBird::ErrorException => ex
31+
puts
32+
puts 'An error occured while creating a conversation:'
33+
puts
34+
35+
ex.errors.each do |error|
36+
puts " code : #{error.code}"
37+
puts " description : #{error.description}"
38+
puts " parameter : #{error.parameter}"
39+
puts
40+
end
41+
end

0 commit comments

Comments
 (0)