npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lcn-twilio-caller

v0.3.0

Published

React component to receive and place voice calls in the browser using Twilio.

Downloads

7

Readme

LCN Twilio Caller

React component to set availability, receive and place voice calls in the browser using Twilio.

npm install lcn-twilio-caller

LCN Twilio Caller

Browser Support

See more about supported browsers and client requirements in the Twilio Docs.

Setup

Twilio requires your app to generate a capability token before use, our component makes a POST request to capabilityEndpoint and expects a token back.

As an example, in Ruby:

def generate_capability
  agent = 'name-of-your-agent'

  capability = Twilio::JWT::ClientCapability.new(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, ttl: 86_400)

  outgoing_scope = Twilio::JWT::ClientCapability::OutgoingClientScope.new(TWILIO_CALL_TWIML_APP, agent)
  capability.add_scope outgoing_scope

  incoming_scope = Twilio::JWT::ClientCapability::IncomingClientScope.new(agent)
  capability.add_scope incoming_scope

  render json: { token: capability.to_s }
end

More details of backend requirements can be found in the Twilio Client SDK documentation.

Locally logging who answers a call

A POST request will also be made to answerEndpoint when a call is answered if you wish to log who answered a call in your application.

As an example, in Ruby:

def answer
  twilio_client = Twilio::REST::Client.new
  twilio_call = twilio_client.calls(params[:call]).fetch

  call = Call.find_by_twilio_id(twilio_call.parent_call_sid)
  call.update({
    user: current_user,
    twilio_status: twilio_call.status
  })  
end

Toggling availability in your backend

You can use the availabilityEndpoint and availability props to allow your backend to manage client availability. For example:

  <TwilioCaller
    available={this.state.accept_incoming_calls}
    availabilityEndpoint={'/caller/availability'}
    ...
  />

... as an example endpoint in Rails:

  def availability
    current_user.toggle!(:accept_incoming_calls)
    render json: { availability: current_user.availability }
  end

Usage

Wrap your React app in the LCNTwilioCaller component then use this.props.dialOutgoing to make calls. dialOutgoing accepts a number of parameters if you wish to pass the call or contact IDs and names between the caller and Twilio, otherwise these can be left blank.

Incoming calls will automatically ring if the user has set themselves available.

import LCNTwilioCaller from 'lcn-twilio-caller';

<LCNTwilioCaller
  capabilityEndpoint={'/caller/capability'}
  answerEndpoint={'/caller/answer'}>

  <App />

  <a
    href="tel:4400"
    onClick={
      this.props.dialOutgoing(
        '+4400...',
        '<Current User ID>',
        '<Contact Name>',
        '<Contact ID.',
        '<Enquiry ID>'
      )
    }
  >
  Call
  </a>

</LCNTwilioCaller>

The Twilio Device can be accessed using this.props.caller. More details can be found in the Twilio Docs.