twilio / twilio-ruby

A Ruby gem for communicating with the Twilio API and generating TwiML
MIT License
1.36k stars 464 forks source link

issue with whatsapp and FB messenger and ruby challenge #2 from twilio-workshop ported from SMS to whatsapp/FB messenger #452

Closed andresmmujica closed 5 years ago

andresmmujica commented 5 years ago

Hi Guys, I'm having an issue when trying to use WhatsApp or Messenger channels in challenge2 from twilio-workshop

https://github.com/kwhinnery/twilio-workshop/tree/master/challenge2/finished

It seems that the issue happens when the channel is not a SMS standard channel, as it's happening with Facebook Messenger too.

I suspect is related to the messenger: or whatsapp: prefix that are not properly handled by the library.

Let me know how to help.

Bests

Version:

Code Snippet

  #if the order is complete, send out a text message
      if order[:complete]
        #client.account.sms.messages.create(
        #if order[:phone].include? "whatsapp:"
        #  order[:phone].tr('whatsapp:','');
        #end
            client.messages.create(
              :to => order[:phone],
              :from => twilio_number,
              :body => 'Su orden ha sido procesada! Su Pizza va en camino :)',
            )
      end

# paste code here

Exception/Log

::1 - - [24/May/2019:10:51:38 -05] "GET / HTTP/1.1" 200 1276
- -> /
2019-05-24 10:51:41 - Twilio::REST::RestError - [HTTP 400] 21212 : Unable to create record
The 'From' number +15555555555 is not a valid phone number, shortcode, or alphanumeric sender ID.
https://www.twilio.com/docs/errors/21212

:
    /Library/Ruby/Gems/2.3.0/gems/twilio-ruby-5.23.0/lib/twilio-ruby/framework/version.rb:150:in `create'
    /Library/Ruby/Gems/2.3.0/gems/twilio-ruby-5.23.0/lib/twilio-ruby/rest/api/v2010/account/message.rb:121:in `create'
    server.rb:51:in `block (2 levels) in <main>'
    server.rb:41:in `each'
    server.rb:41:in `block in <main>'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1635:in `call'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1635:in `block in compile!'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:992:in `block (3 levels) in route!'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1011:in `route_eval'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:992:in `block (2 levels) in route!'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1040:in `block in process_route'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1038:in `catch'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1038:in `process_route'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:990:in `block in route!'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:989:in `each'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:989:in `route!'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1097:in `block in dispatch!'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1076:in `block in invoke'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1076:in `catch'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1076:in `invoke'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1094:in `dispatch!'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:924:in `block in call!'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1076:in `block in invoke'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1076:in `catch'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1076:in `invoke'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:924:in `call!'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:913:in `call'
    /Library/Ruby/Gems/2.3.0/gems/rack-protection-2.0.5/lib/rack/protection/xss_header.rb:18:in `call'
    /Library/Ruby/Gems/2.3.0/gems/rack-protection-2.0.5/lib/rack/protection/path_traversal.rb:16:in `call'
    /Library/Ruby/Gems/2.3.0/gems/rack-protection-2.0.5/lib/rack/protection/json_csrf.rb:26:in `call'
    /Library/Ruby/Gems/2.3.0/gems/rack-protection-2.0.5/lib/rack/protection/base.rb:50:in `call'
    /Library/Ruby/Gems/2.3.0/gems/rack-protection-2.0.5/lib/rack/protection/base.rb:50:in `call'
    /Library/Ruby/Gems/2.3.0/gems/rack-protection-2.0.5/lib/rack/protection/frame_options.rb:31:in `call'
    /Library/Ruby/Gems/2.3.0/gems/rack-2.0.7/lib/rack/logger.rb:15:in `call'
    /Library/Ruby/Gems/2.3.0/gems/rack-2.0.7/lib/rack/common_logger.rb:33:in `call'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:231:in `call'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:224:in `call'
    /Library/Ruby/Gems/2.3.0/gems/rack-2.0.7/lib/rack/head.rb:12:in `call'
    /Library/Ruby/Gems/2.3.0/gems/rack-2.0.7/lib/rack/method_override.rb:22:in `call'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/show_exceptions.rb:22:in `call'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:194:in `call'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1957:in `call'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1502:in `block in call'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1729:in `synchronize'
    /Library/Ruby/Gems/2.3.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1502:in `call'
    /Library/Ruby/Gems/2.3.0/gems/rack-2.0.7/lib/rack/handler/webrick.rb:86:in `service'
    /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
    /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/webrick/server.rb:314:in `block in start_thread'
::1 - - [24/May/2019:10:51:40 -05] "POST /fillOrder HTTP/1.1" 500 141863
http://.ngrok.io/ -> /fillOrder

Steps to Reproduce

  1. replicate challenge2 from twilio-workshop pointing whatsapp or fb messenger webhooks url to the server.
  2. send a message from whatsapp or fb
  3. mark order completed in the website

Feature Request

If this is a feature request, make sure you search Issues for an existing request before creating a new one!

childish-sambino commented 5 years ago

When sending to WhatsApp, both the to and from numbers need to have the whatsapp: prefix.