Giter VIP home page Giter VIP logo

groups-quickstart's Introduction

This application is designed for demonstrating the capabilities of the Messaging Sessions API, particularly how Chat users in the browser can exchange messages seamlessly with others on SMS or WhatsApp.

Configuring and getting started.

This demo requires a Twilio account. You'll need to collect some credentials from the Twilio Console:

  • Your Account SID A string in the form ACxx, accessible from the Dashboard
  • An API/Signing Key Pair These are an SKxx sid and the accompanying secret, part of the Runtime. A standard key is fine.
  • Your Account's Chat Service SID An ISxx SID which is best determined by creating a new session.

Creating a new session is straightforward. Check out the code samples or run something like this from your command line:

curl -X POST \
    https://messaging.twilio.com/v1/Sessions/ \
    --user SKxx:secret
    -d MessagingServiceSid=MGxx

In the response, look for service_sid; this is the value you want. Additionally, save the value in sid -- this will come in handy later on.

Create a .env file.

Clone this repository. In the working directory, copy the .env.example file to a new file called .env. Inject the information you gathered above into the appropriate fields. It should look something like this: TWILIO_ACCOUNT_SID=AC3c96f11c8c1942ab02eca915b1debd27 TWILIO_API_KEY=SK8c1942ab02eca915b1debd273c96f11c TWILIO_API_SECRET=yoursecret TWILIO_CHAT_SERVICE_SID=ISe9216d04b78c40229899ffd93aff33c4

Upgrade node.js and install dependencies

Your system may not have a particularly recent version of node.js installed by default. This demo requires Node.js v10 or higher. Use the package manager most appropriate on your system. On Mac OS, you probably want brew upgrade node.js.

Test this by running npm install. This should execute successfully to completion.

Start the Demo

Run npm start. This will automatically start two processes:

  1. One starts a token server, using the credentials from your .env file.
  2. The other runs a react app. Your browser should open automatically to https://localhost:3000/

Log in with a random identity string like testfelix. You'll know everything is working if the text "You are connected." appears on the top right.

Add a Chat Participant

Using the Sessions Participants REST API, create a new Chat participant by passing the Identity= parameter on the same session you'd created before.

curl -X POST https://messaging.twilio.com/v1/Sessions/CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Participants \
    --data-urlencode "Identity=<chat-user-identity>" \
    -u SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:secret

In the browser, you should see the your session pop up within a second or two. Congratulations! You're in a session.

Add an SMS Participant

Chatting with yourself isn't as satisfying without the comforting pling of SMS arrival. Visit the Sessions SMS quickstart to create a phone number. When you finally start adding participants, use the same session SID you used above to get started.

If all goes well, you'll have bridged an SMS user with a Chat user, all in a few requests!

Next Steps

From this point, you have all you need to explore the power of declarative conversational messaging. Using the tools we've explored so far, you can:

  • Transfer a user from webchat to sms
  • Add a third, fourth, or even a fifth simultaneous participant (up to 20!)
  • Set up the Programmable Chat SDK in a mobile app (iOS or Android), for the same experience
  • Add a WhatsApp participant (Coming soon!)
  • Attach to Group MMS conversations (Coming soon!)
  • Exchange media and rich content (Coming soon!)

Be advised that Sessions is under active development and the APIs you use here may change.

groups-quickstart's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.