Coder Social home page Coder Social logo

twiliodeved / sdk-starter-node Goto Github PK

View Code? Open in Web Editor NEW
81.0 20.0 73.0 769 KB

Demo application showcasing Twilio API usage in Node.js

Home Page: https://www.twilio.com/docs

License: MIT License

JavaScript 66.95% CSS 8.73% HTML 22.63% Shell 1.69%

sdk-starter-node's Introduction

Twilio

Twilio SDK Starter Application for Node.js

Node.js CI

This sample project demonstrates how to use Twilio APIs in a Node.js web application. Once the app is up and running, check out the home page to see which demos you can run. You'll find examples for Chat, Sync, and Notify.

Let's get started!

Configure the sample application

To run the application, you'll need to gather your Twilio account credentials and configure them in a file named .env. To create this file from an example template, do the following in your Terminal.

cp .env.example .env

Open .env in your favorite text editor and configure the following values.

Configure account information

Every sample in the demo requires some basic credentials from your Twilio account. Configure these first.

Config Value Description
TWILIO_ACCOUNT_SID Your primary Twilio account identifier - find this in the console here.
TWILIO_API_KEY Used to authenticate - generate one here.
TWILIO_API_SECRET Used to authenticate - just like the above, you'll get one here.

A Note on API Keys

When you generate an API key pair at the URLs above, your API Secret will only be shown once - make sure to save this information in a secure location, or possibly your ~/.bash_profile.

Configure product-specific settings

Depending on which demos you'd like to run, you may need to configure a few more values in your .env file.

Configuring Twilio Sync

Twilio Sync works out of the box, using default settings per account. Once you have your API keys configured, execute npm install; npm run start and open a browser!

Configuring Twilio Chat

In addition to the above, you'll need to generate a Chat Service in the Twilio Console. Put the result in your .env file.

Config Value Where to get one.
TWILIO_CHAT_SERVICE_SID Chat

Configuring Twilio Notify

You will need to create a Notify Service and add at least one credential on the Mobile Push Credential screen (such as Apple Push Notification Service or Firebase Cloud Messaging for Android) to send notifications using Notify.

Config Value Where to get one.
TWILIO_NOTIFICATION_SERVICE_SID Generate one in the Notify Console and put this in your .env file.
A Push Credential Generate one with Apple or Google and configure it as a Notify credential.

Once you've done that, run the application and open a browser!

Run the sample application

Now that the application is configured, we need to install our dependencies from npm.

npm install

Now we should be all set! Run the application using the node command.

npm start

Your application should now be running at http://localhost:3000/.

Home Screen

Check your config values, and follow the links to the demo applications!

Running the SDK Starter Kit with ngrok

If you are going to connect to this SDK Starter Kit with a mobile app (and you should try it out!), your phone won't be able to access localhost directly. You'll need to create a publicly accessible URL using a tool like ngrok to send HTTP/HTTPS traffic to a server running on your localhost. Use HTTPS to make web connections that retrieve a Twilio access token.

ngrok http 3000

Meta

  • No warranty expressed or implied. Software is as is. Diggity.
  • MIT License
  • Lovingly crafted by Twilio Developer Education.

sdk-starter-node's People

Contributors

alexisbcc avatar atampere avatar dependabot-preview[bot] avatar devidliik avatar dkundel avatar dprothero avatar hortega avatar jandusek avatar jefflinwood avatar joliveros avatar kwhinnery avatar micaswyers avatar pkamp3 avatar plohm12 avatar po5i avatar rbeiter avatar saipanindra avatar smendes avatar well1791 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sdk-starter-node's Issues

Error creating the chat client

When following the setup instructions, after running npm start I see the following in my terminal

Screen Shot 2022-04-14 at 11 57 04 AM

When I then go to local host (http://localhost:3000/chat/) I then see the following:

Screen Shot 2022-04-14 at 12 07 58 PM

I have set my env variables and ensured my chat service is present in the Twilio console. API key was also newly generated.

env

Some usage questions

We are building an app with twilio chat, one problem is that, the mobile app and web app we did, will have sync the chat history all the time, the client want to save chat channel history in firebase, that's a problem.

How to do it with twilio service and firebase same time, it could be complex.

Also another question is that, even though I have read some of the javascript SDK, still didn't get the way how channel works.

For example, if a twilio client create a channel, then when should it to be closed? Or it keep opening?

Also, if a client doesn't use explicit api to leave the channel, what happened? Does this user still in channel? Still count in the total users of the channel?

When test this starter, see this issue, as the channel room general will be full very soon, even though it only have three users, if the app do join the channel many times without leaving it...

If someone can explain more, would be great to know how to use twilio chat properly..

Wrong URL in SDK

"the requested resource /Services//Notifications was not found" is reported when trying out the Notify functionality.

Chat example does not work

Hi,

I tried to run the chat example and I got this error in the console:

image

I followed step by step the readme.
What should I do to make it work?

Thanks.

Misleading documentation

Hi, apologies if this is not the best place to report this issue.

Here is my situation: my team and I were following the instructions here -- https://www.twilio.com/docs/api/notify/guides/messenger-notifications -- for the Facebook messenger integration quickstart.

About half way down the page, the docs mention a sample app on Github, linked to here: https://github.com/TwilioDevEd/notifications-quickstart-node, and subsequent directions in the aforementioned cos refer to files from that repository (e.g. public/facebook-messenger.html).

However, visiting that GH repo I see that it is deprecated, and refers the reader instead to https://github.com/TwilioDevEd/sdk-starter-node.

Yet at https://github.com/TwilioDevEd/sdk-starter-node there nothing about Facebook messenger integration, and the sample public/facebook-messenger.html is absent from the repo. You can see this file was deleted from the other repo at commit TwilioDevEd/notifications-quickstart-node@8d1c19d.

So, it seems like either this repo needs to be updated to reflect the docs at https://www.twilio.com/docs/api/notify/guides/messenger-notifications, or those docs need to be updated.

Thanks

Build failing

... and struggling to get the chat demo working. Pretty sure the config is correct.

Unsure if build issue is related but thought you should know.

How chat events from front end are consumed in NodejS backend

How chat events from front end are consumed in NodejS backend. Because I am seeing on twilio docs its built in APIs for chat room creation, adding members, send messages to channel.

const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.chat.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.channels('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.messages
.create({body: 'MESSAGE'})
.then(message => console.log(message.sid));

Are we sending messages through above API or we have events for same.

SyntaxError: Unexpected token

Hello ,

I have set up this source in my local system, I am using ubuntu.
I have done configuration in .env file still i am getting error like below when i am run following command : node app.js
npm version : 3.5.2
node version : 4.2.6
Error :
/backup/html/sdk-starter-node/src/router.js:3
const {registerBind, sendNotification} = require('./notification_handler');
SyntaxError: Unexpected token {

Can you please suggest me solution for it?

Chat does not work

Followed the instructions and added the chat service SID.

getting this error
screen shot 2018-07-25 at 11 34 19 am

With twilio API in vuejs2 app I got error client.on is not a function

I want to use twilio API in my vuejs2 app looking at demo https://github.com/TwilioDevEd/sdk-starter-node:

I got client object with Twilio credentials, but next I want to assign tokenAboutToExpire with code like :

const client = new Twilio(
    process.env.VUE_APP_TWILIO_API_KEY,
    process.env.VUE_APP_TWILIO_API_SECRET,
    {
        accountSid: process.env.VUE_APP_TWILIO_ACCOUNT_SID,
    }
)
console.log('client::')
console.log(client)
console.log('client.chat::')
console.log(client.chat)

client.on("tokenAboutToExpire", async () => { // Error line
// client.chat.on("tokenAboutToExpire", async () => { // If to uncomment this line 
    const token = await this.fetchChatToken()
    client.updateToken(token)
})

and got error:

Uncaught (in promise) TypeError: client.on is not a function
    at _callee3$ (usersChat.vue?ec5f:264)
    at tryCatch (runtime.js?96cf:63)
    at Generator.invoke [as _invoke] (runtime.js?96cf:293)

and in the console I see that I have client and client.chat : https://prnt.sc/w4frzp
What is wrong?
Is it invalid client object?

Thanks!

WebSocket connection issue

Hello everyone,

I have followed the Read Me file in terms of getting started and setting up my .env variables.
Everything looks great but I keep running into this error when checking out the Chat tab.

I am working behind a strict company Firewall. Could this be the issue?

Screenshot 2022-02-24 102221

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.