From d515da839e056b24cd85aea7247c4b7c04914d96 Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Thu, 21 May 2020 08:12:26 +0400 Subject: [PATCH 01/16] Updated the stealth dependency to version 2.0 --- stealth-twilio.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stealth-twilio.gemspec b/stealth-twilio.gemspec index 9b17135..c03fde5 100644 --- a/stealth-twilio.gemspec +++ b/stealth-twilio.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |s| s.author = 'Mauricio Gomes' s.email = 'mauricio@edge14.com' - s.add_dependency 'stealth', '< 2.0' + s.add_dependency 'stealth', '~> 2.0' s.add_dependency 'twilio-ruby', '~> 5.5' s.add_development_dependency 'rspec', '~> 3.6' From 61b5bb00d23639079810ca6f055197ef5ff9dd86 Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Sat, 23 May 2020 10:23:22 +0400 Subject: [PATCH 02/16] Added a generate_suggestions method in reply_handler --- lib/stealth/services/twilio/reply_handler.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/stealth/services/twilio/reply_handler.rb b/lib/stealth/services/twilio/reply_handler.rb index bcedd25..04b8a1a 100644 --- a/lib/stealth/services/twilio/reply_handler.rb +++ b/lib/stealth/services/twilio/reply_handler.rb @@ -18,6 +18,11 @@ def text check_text_length format_response({ body: reply['text'] }) + + if reply['suggestions'].present? + sms_suggestions = generate_suggestions(suggestions: reply['suggestions']) + template["message"]["quick_replies"] = fb_suggestions + end end def image @@ -61,6 +66,20 @@ def format_response(response) response.merge(sender_info) end + def generate_suggestions(suggestions:) + quick_replies = suggestions.collect do |suggestion| + + quick_reply = { + "content_type" => "text", + "title" => suggestion["text"] + } + + quick_reply + end + + quick_replies + end + end end From 0588ebb63c78b64916a35dbab0bd0dafa76920ce Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Sat, 23 May 2020 10:47:35 +0400 Subject: [PATCH 03/16] Added template --- lib/stealth/services/twilio/reply_handler.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/stealth/services/twilio/reply_handler.rb b/lib/stealth/services/twilio/reply_handler.rb index 04b8a1a..46ee0c6 100644 --- a/lib/stealth/services/twilio/reply_handler.rb +++ b/lib/stealth/services/twilio/reply_handler.rb @@ -17,12 +17,15 @@ def initialize(recipient_id: nil, reply: nil) def text check_text_length - format_response({ body: reply['text'] }) + + template = unstructured_template + template['message']['text'] = reply['text'] if reply['suggestions'].present? sms_suggestions = generate_suggestions(suggestions: reply['suggestions']) - template["message"]["quick_replies"] = fb_suggestions + template["message"]["quick_replies"] = sms_suggestions end + format_response({ body: reply['text'] }) end def image @@ -66,6 +69,15 @@ def format_response(response) response.merge(sender_info) end + def unstructured_template + { + "recipient" => { + "id" => recipient_id + }, + "message" => { } + } + end + def generate_suggestions(suggestions:) quick_replies = suggestions.collect do |suggestion| From a7767e28a98bd32b2d1779facedd74fcd77955db Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Mon, 25 May 2020 12:10:22 +0400 Subject: [PATCH 04/16] Went back to the previous version --- lib/stealth/services/twilio/reply_handler.rb | 31 -------------------- 1 file changed, 31 deletions(-) diff --git a/lib/stealth/services/twilio/reply_handler.rb b/lib/stealth/services/twilio/reply_handler.rb index 46ee0c6..bcedd25 100644 --- a/lib/stealth/services/twilio/reply_handler.rb +++ b/lib/stealth/services/twilio/reply_handler.rb @@ -17,14 +17,6 @@ def initialize(recipient_id: nil, reply: nil) def text check_text_length - - template = unstructured_template - template['message']['text'] = reply['text'] - - if reply['suggestions'].present? - sms_suggestions = generate_suggestions(suggestions: reply['suggestions']) - template["message"]["quick_replies"] = sms_suggestions - end format_response({ body: reply['text'] }) end @@ -69,29 +61,6 @@ def format_response(response) response.merge(sender_info) end - def unstructured_template - { - "recipient" => { - "id" => recipient_id - }, - "message" => { } - } - end - - def generate_suggestions(suggestions:) - quick_replies = suggestions.collect do |suggestion| - - quick_reply = { - "content_type" => "text", - "title" => suggestion["text"] - } - - quick_reply - end - - quick_replies - end - end end From 9dccc9e7fc5b66c98a21212e213f7fb869c0e9dc Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Fri, 26 Mar 2021 10:03:28 +0400 Subject: [PATCH 05/16] Add a TwilioServiceMessage class, not finalized yet --- lib/stealth/services/twilio/client.rb | 2 ++ lib/stealth/services/twilio/message_handler.rb | 3 ++- .../services/twilio/twilio_service_message.rb | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 lib/stealth/services/twilio/twilio_service_message.rb diff --git a/lib/stealth/services/twilio/client.rb b/lib/stealth/services/twilio/client.rb index 555b7ce..6bc76a2 100644 --- a/lib/stealth/services/twilio/client.rb +++ b/lib/stealth/services/twilio/client.rb @@ -5,6 +5,8 @@ require 'stealth/services/twilio/message_handler' require 'stealth/services/twilio/reply_handler' +require 'stealth/services/twilio/twilio_service_message' + require 'stealth/services/twilio/setup' module Stealth diff --git a/lib/stealth/services/twilio/message_handler.rb b/lib/stealth/services/twilio/message_handler.rb index ea911bd..c78a542 100644 --- a/lib/stealth/services/twilio/message_handler.rb +++ b/lib/stealth/services/twilio/message_handler.rb @@ -24,10 +24,11 @@ def coordinate end def process - @service_message = ServiceMessage.new(service: 'twilio') + @service_message = TwilioServiceMessage.new(service: 'twilio') service_message.sender_id = params['From'] service_message.target_id = params['To'] service_message.message = params['Body'] + service_message.display_name = params['ProfileName'] # Check for media attachments attachment_count = params['NumMedia'].to_i diff --git a/lib/stealth/services/twilio/twilio_service_message.rb b/lib/stealth/services/twilio/twilio_service_message.rb new file mode 100644 index 0000000..15b6887 --- /dev/null +++ b/lib/stealth/services/twilio/twilio_service_message.rb @@ -0,0 +1,14 @@ +module Stealth + module Services + module Twilio + class TwilioServiceMessage < Stealth::ServiceMessage + attr_accessor :display_name + + def initialize(service:) + @service = service + @display_name = display_name + end + end + end + end +end From 30c9648bd5b507e0234eb7ebc4c4db28255ea953 Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Fri, 26 Mar 2021 17:49:57 +0400 Subject: [PATCH 06/16] translated into spanish --- lib/stealth/services/twilio/reply_handler.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/stealth/services/twilio/reply_handler.rb b/lib/stealth/services/twilio/reply_handler.rb index 4f9c756..c0421da 100644 --- a/lib/stealth/services/twilio/reply_handler.rb +++ b/lib/stealth/services/twilio/reply_handler.rb @@ -6,7 +6,7 @@ module Services module Twilio class ReplyHandler < Stealth::Services::BaseReplyHandler - ALPHA_ORDINALS = ('A'..'Z').to_a.freeze + # ALPHA_ORDINALS = ('A'..'Z').to_a.freeze attr_reader :recipient_id, :reply @@ -26,13 +26,14 @@ def text if suggestions.present? translated_reply = [ translated_reply, - 'Reply with:' + 'Responde con nĂºmero:' ].join("\n\n") suggestions.each_with_index do |suggestion, i| translated_reply = [ translated_reply, - "\"#{ALPHA_ORDINALS[i]}\" for #{suggestion}" + "#{i + 1} para #{suggestion}" + # "\"#{ALPHA_ORDINALS[i]}\" for #{suggestion}" ].join("\n") end end @@ -109,7 +110,7 @@ def generate_buttons(buttons:) when 'url' "#{button['text']}: #{button['url']}" when 'payload' - "To #{button['text'].downcase}: Text #{button['payload'].upcase}" + "Para #{button['text'].downcase}: Texto #{button['payload'].upcase}" when 'call' "#{button['text']}: #{button['phone_number']}" else # Don't raise for unsupported buttons From 8c073881c6ef1c560653b80fe5b968060b0ddd6a Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Fri, 26 Mar 2021 19:32:32 +0400 Subject: [PATCH 07/16] Add location params in twilio_service_message --- lib/stealth/services/twilio/message_handler.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/stealth/services/twilio/message_handler.rb b/lib/stealth/services/twilio/message_handler.rb index c78a542..235ec91 100644 --- a/lib/stealth/services/twilio/message_handler.rb +++ b/lib/stealth/services/twilio/message_handler.rb @@ -29,6 +29,7 @@ def process service_message.target_id = params['To'] service_message.message = params['Body'] service_message.display_name = params['ProfileName'] + service_message.location = { latitude: params['Latitude'], longitude: params['Longitude'] } # Check for media attachments attachment_count = params['NumMedia'].to_i From c752393f1bba9a24eff425332b6f4bef82fecec7 Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Fri, 26 Mar 2021 19:36:05 +0400 Subject: [PATCH 08/16] Delete unecessary initialize method --- lib/stealth/services/twilio/twilio_service_message.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/stealth/services/twilio/twilio_service_message.rb b/lib/stealth/services/twilio/twilio_service_message.rb index 15b6887..984d69e 100644 --- a/lib/stealth/services/twilio/twilio_service_message.rb +++ b/lib/stealth/services/twilio/twilio_service_message.rb @@ -4,10 +4,6 @@ module Twilio class TwilioServiceMessage < Stealth::ServiceMessage attr_accessor :display_name - def initialize(service:) - @service = service - @display_name = display_name - end end end end From ca6fbdc82c8ea4d6031f5338b75569186592863b Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Fri, 26 Mar 2021 19:57:16 +0400 Subject: [PATCH 09/16] Add a reply location, not finalized yet --- lib/stealth/services/twilio/reply_handler.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/stealth/services/twilio/reply_handler.rb b/lib/stealth/services/twilio/reply_handler.rb index c0421da..dc28df6 100644 --- a/lib/stealth/services/twilio/reply_handler.rb +++ b/lib/stealth/services/twilio/reply_handler.rb @@ -74,6 +74,12 @@ def file format_response({ body: reply['text'], media_url: reply['file_url'] }) end + # def location + # check_text_length + # persistent_action: ['geo:37.787890,-122.391664|375 Beale St'] + # format_response({ body: reply['text'], latitude: reply['latitude'], longitude: reply['longitude'] }) + # end + def delay end From 1c9118a255974597b4fbe939b0803605ecc0f17c Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Sat, 27 Mar 2021 13:58:48 +0400 Subject: [PATCH 10/16] Finalize whatsapp reply location --- lib/stealth/services/twilio/reply_handler.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/stealth/services/twilio/reply_handler.rb b/lib/stealth/services/twilio/reply_handler.rb index dc28df6..2b917bf 100644 --- a/lib/stealth/services/twilio/reply_handler.rb +++ b/lib/stealth/services/twilio/reply_handler.rb @@ -74,11 +74,10 @@ def file format_response({ body: reply['text'], media_url: reply['file_url'] }) end - # def location - # check_text_length - # persistent_action: ['geo:37.787890,-122.391664|375 Beale St'] - # format_response({ body: reply['text'], latitude: reply['latitude'], longitude: reply['longitude'] }) - # end + def location + check_text_length + format_response({ body: reply['text'], persistent_action: ["geo:#{reply['latitude']},#{reply['longitude']}|#{reply['label']}"] }) + end def delay From 5aa9b6336acc5b64cf55882534a56746aa7a3857 Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Fri, 26 Mar 2021 10:03:28 +0400 Subject: [PATCH 11/16] Add a TwilioServiceMessage class to capture whatsapp user name --- lib/stealth/services/twilio/client.rb | 2 ++ lib/stealth/services/twilio/message_handler.rb | 3 ++- lib/stealth/services/twilio/twilio_service_message.rb | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 lib/stealth/services/twilio/twilio_service_message.rb diff --git a/lib/stealth/services/twilio/client.rb b/lib/stealth/services/twilio/client.rb index 555b7ce..6bc76a2 100644 --- a/lib/stealth/services/twilio/client.rb +++ b/lib/stealth/services/twilio/client.rb @@ -5,6 +5,8 @@ require 'stealth/services/twilio/message_handler' require 'stealth/services/twilio/reply_handler' +require 'stealth/services/twilio/twilio_service_message' + require 'stealth/services/twilio/setup' module Stealth diff --git a/lib/stealth/services/twilio/message_handler.rb b/lib/stealth/services/twilio/message_handler.rb index ea911bd..c78a542 100644 --- a/lib/stealth/services/twilio/message_handler.rb +++ b/lib/stealth/services/twilio/message_handler.rb @@ -24,10 +24,11 @@ def coordinate end def process - @service_message = ServiceMessage.new(service: 'twilio') + @service_message = TwilioServiceMessage.new(service: 'twilio') service_message.sender_id = params['From'] service_message.target_id = params['To'] service_message.message = params['Body'] + service_message.display_name = params['ProfileName'] # Check for media attachments attachment_count = params['NumMedia'].to_i diff --git a/lib/stealth/services/twilio/twilio_service_message.rb b/lib/stealth/services/twilio/twilio_service_message.rb new file mode 100644 index 0000000..984d69e --- /dev/null +++ b/lib/stealth/services/twilio/twilio_service_message.rb @@ -0,0 +1,10 @@ +module Stealth + module Services + module Twilio + class TwilioServiceMessage < Stealth::ServiceMessage + attr_accessor :display_name + + end + end + end +end From 892d8e1f8f3dbb4b69ae75036684829055eab8b3 Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Fri, 19 May 2023 10:12:39 +0400 Subject: [PATCH 12/16] Uncomment ALPHA_ORDINALS --- lib/stealth/services/twilio/reply_handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stealth/services/twilio/reply_handler.rb b/lib/stealth/services/twilio/reply_handler.rb index fa83c3c..2626a31 100644 --- a/lib/stealth/services/twilio/reply_handler.rb +++ b/lib/stealth/services/twilio/reply_handler.rb @@ -6,7 +6,7 @@ module Services module Twilio class ReplyHandler < Stealth::Services::BaseReplyHandler - # ALPHA_ORDINALS = ('A'..'Z').to_a.freeze + ALPHA_ORDINALS = ('A'..'Z').to_a.freeze attr_reader :recipient_id, :reply, :translated_reply From a2c09bd5a70b03500ee3359018be2507344e4365 Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Fri, 19 May 2023 10:22:02 +0400 Subject: [PATCH 13/16] Not using ALPHA_ORDINALS --- lib/stealth/services/twilio/reply_handler.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/stealth/services/twilio/reply_handler.rb b/lib/stealth/services/twilio/reply_handler.rb index 2626a31..1cbf6bb 100644 --- a/lib/stealth/services/twilio/reply_handler.rb +++ b/lib/stealth/services/twilio/reply_handler.rb @@ -6,7 +6,7 @@ module Services module Twilio class ReplyHandler < Stealth::Services::BaseReplyHandler - ALPHA_ORDINALS = ('A'..'Z').to_a.freeze + # ALPHA_ORDINALS = ('A'..'Z').to_a.freeze attr_reader :recipient_id, :reply, :translated_reply @@ -32,7 +32,8 @@ def text suggestions.each_with_index do |suggestion, i| @translated_reply = [ @translated_reply, - "\"#{ALPHA_ORDINALS[i]}\" for #{suggestion}" + "#{i + 1} for #{suggestion}" + # "\"#{ALPHA_ORDINALS[i]}\" for #{suggestion}" ].join("\n") end end From df7ddfc4209e37de6362ffe5be1d8eaac3cea6d7 Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Fri, 19 May 2023 10:30:41 +0400 Subject: [PATCH 14/16] Translate --- lib/stealth/services/twilio/reply_handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stealth/services/twilio/reply_handler.rb b/lib/stealth/services/twilio/reply_handler.rb index 1cbf6bb..09e0056 100644 --- a/lib/stealth/services/twilio/reply_handler.rb +++ b/lib/stealth/services/twilio/reply_handler.rb @@ -115,7 +115,7 @@ def generate_buttons(buttons:) when 'url' "#{button['text']}: #{button['url']}" when 'payload' - "Para #{button['text'].downcase}: Texto #{button['payload'].upcase}" + "To #{button['text'].downcase}: Text #{button['payload'].upcase}" when 'call' "#{button['text']}: #{button['phone_number']}" else # Don't raise for unsupported buttons From 51926d404b98420498856725995d1c041a22d1de Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Fri, 19 May 2023 10:34:39 +0400 Subject: [PATCH 15/16] Back to ALPHA_ORDINALS --- lib/stealth/services/twilio/reply_handler.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/stealth/services/twilio/reply_handler.rb b/lib/stealth/services/twilio/reply_handler.rb index 09e0056..f78df6b 100644 --- a/lib/stealth/services/twilio/reply_handler.rb +++ b/lib/stealth/services/twilio/reply_handler.rb @@ -6,7 +6,7 @@ module Services module Twilio class ReplyHandler < Stealth::Services::BaseReplyHandler - # ALPHA_ORDINALS = ('A'..'Z').to_a.freeze + ALPHA_ORDINALS = ('A'..'Z').to_a.freeze attr_reader :recipient_id, :reply, :translated_reply @@ -32,8 +32,7 @@ def text suggestions.each_with_index do |suggestion, i| @translated_reply = [ @translated_reply, - "#{i + 1} for #{suggestion}" - # "\"#{ALPHA_ORDINALS[i]}\" for #{suggestion}" + "\"#{ALPHA_ORDINALS[i]}\" for #{suggestion}" ].join("\n") end end From ccd78dc04fbc5aec921f36b64db96bca15ad52a5 Mon Sep 17 00:00:00 2001 From: Emilie Morissette Date: Fri, 19 May 2023 10:40:23 +0400 Subject: [PATCH 16/16] Uncomment ALPHA_ORDINALS --- lib/stealth/services/twilio/reply_handler.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/stealth/services/twilio/reply_handler.rb b/lib/stealth/services/twilio/reply_handler.rb index fa83c3c..f78df6b 100644 --- a/lib/stealth/services/twilio/reply_handler.rb +++ b/lib/stealth/services/twilio/reply_handler.rb @@ -6,7 +6,7 @@ module Services module Twilio class ReplyHandler < Stealth::Services::BaseReplyHandler - # ALPHA_ORDINALS = ('A'..'Z').to_a.freeze + ALPHA_ORDINALS = ('A'..'Z').to_a.freeze attr_reader :recipient_id, :reply, :translated_reply @@ -114,7 +114,7 @@ def generate_buttons(buttons:) when 'url' "#{button['text']}: #{button['url']}" when 'payload' - "Para #{button['text'].downcase}: Texto #{button['payload'].upcase}" + "To #{button['text'].downcase}: Text #{button['payload'].upcase}" when 'call' "#{button['text']}: #{button['phone_number']}" else # Don't raise for unsupported buttons