Last active
December 14, 2015 16:38
-
-
Save phstc/5116040 to your computer and use it in GitHub Desktop.
Call me maybe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul id="user-list" data-token="eyJ0..."> | |
<li> | |
Pablo Cantero - <a href="#" rel="phone-number">+551199...</a> | |
</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//static.twilio.com/libs/twiliojs/1.1/twilio.min.js"></script> | |
<ul id="user-list" data-token="<%= token %>"> | |
<% @users.each do |user| %> | |
<li> | |
<%= user.name %> - <a href="#" rel="phone-number"><%= user.name %></a> | |
</li> | |
<% end %> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
Twilio.Device.setup($("#user-list").data("token")); | |
$("a[rel=phone-number]").on("click", function(e){ | |
e.preventDefault(); | |
if(Twilio.Device.status() !== "ready"){ | |
Twilio.Device.disconnectAll(); | |
return; | |
} | |
$this = $(e.target); | |
Twilio.Device.connect($this.text()); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ -> | |
Twilio.Device.setup $("#user-list").data "token" | |
$("a[rel=phone-number]").on "click", (e) -> | |
e.preventDefault() | |
if Twilio.Device.status() != "ready" | |
Twilio.Device.disconnectAll() | |
return | |
$this = $ e.target | |
Twilio.Device.connect $this.text() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gemfile: gem "twilio-ruby" | |
class UsersController < ApplicationController | |
def index | |
account_sid = ENV["TWILIO_ACCOUNT_SID"] | |
auth_token = ENV["TWILIO_AUTH_TOKEN"] | |
twiml_app_sid = ENV["TWILIO_TWIML_APP"] | |
capability = Twilio::Util::Capability.new account_sid, auth_token | |
capability.allow_client_outgoing twiml_app_sid | |
@token = capability.generate | |
@users = User.all | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment