Code Monkey home page Code Monkey logo

appointment-reminders-node's Introduction

Twilio

Appointment Reminders. Powered by Twilio - Node.js/Express

Node.js CI

Use Twilio to create automatic appointment reminders for your business users. For a step-by-step tutorial see twilio docs.

Local development

First you need to install Node.js.

  1. This sample application stores data in a MongoDB database using Mongoose. You can download and run MongoDB yourself (on OS X, Linux or Windows).

    On OS X, maybe the easiest way to get MongoDB running locally is to install it via Homebrew.

    brew tap mongodb/brew
    brew install mongodb-community

    You should then be able to run a local server with:

    mongod

To run the app locally:

  1. Clone this repository and cd into it

    git clone [email protected]:TwilioDevEd/appointment-reminders-node.git
    
    cd appointment-reminders-node
  2. Install dependencies

    npm install
  3. Copy the sample configuration file and edit it to match your configuration

    cp .env.example .env

    You can find your TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN in your Twilio Account Settings. You will also need a TWILIO_PHONE_NUMBER, which you may find here.

    You can reuse the MONGO_URL_TEST for MONGO_URL for most default installs. Otherwise, use your production Mongo installation.

    Run source .env to export the environment variables

  4. Run the application

    npm start

    Alternatively you might also consider using nodemon for this. It works just like the node command but automatically restarts your application when you change any source code files.

    npm install -g nodemon
    nodemon ./bin/www
  5. Check it out at http://localhost:3000

That's it

Run the tests

You can run the tests locally by typing

npm test

Meta

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

appointment-reminders-node's People

Contributors

alexisbcc avatar bld010 avatar dependabot-preview[bot] avatar dprothero avatar garethpaul avatar hortega avatar jefflinwood avatar joliveros avatar kathyguerron avatar mateustav avatar mcelicalderon avatar nebtrx avatar onlywade avatar pkamp3 avatar smendes 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

Watchers

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

appointment-reminders-node's Issues

Config.js error

require('dotenv-safe').load(); needs to change to require('dotenv-safe').config();

brew install mongodb no longer maintained

Mongodb was removed from the Homebrew core formulas since it was migrated to a non-open source license.

Fortunately, the team of mongodb is maintaining a custom Homebrew tap. You can uninstall the old mongodb and reinstall the new one from the new tap.

brew services stop mongodb
brew uninstall mongodb

brew tap mongodb/brew
brew install mongodb-community
brew services start mongodb-community
Check mongodb/homebrew-brew for more info.

Cannot read property 'utc' of undefined

Hello! I'm trying to recreate this but the notifications aren't being sent. This is the error I get while server is running:

[grunt-develop] > Running Send Notifications Worker for 2017-02-07T14:04:00-05:00
[grunt-develop] > (node:20477) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'utc' of undefined

I can't figure how/why this is happening. Not getting any other errors, notications are being saved to db properly. I suspected something is going on in the models/appointment.js:

`var mongoose = require('mongoose');
var moment = require('moment');
var twilio = require('twilio');

var AppointmentSchema = new mongoose.Schema({
  phoneNumber: String,
  notification : String,
  timeZone: String,
  time : {type : Date, index : true}
});

AppointmentSchema.methods.requiresNotification = function (date) {
  return Math.round(moment.duration(moment(this.time).tz(this.timeZone).utc()
                          .diff(moment(date).utc())
                        ).asMinutes()) === this.notification;
};

AppointmentSchema.statics.sendNotifications = function(callback) {

  // now
  var searchDate = new Date();
  Appointment
    .find()
    .then(function (appointments) {
      appointments = appointments.filter(function(appointment) {
              return appointment.requiresNotification(searchDate);
      });
      if (appointments.length > 0) {
        sendNotifications(appointments);
      }
    });

    // Send messages to all appoinment owners via Twilio
    function sendNotifications(docs) {
        var client = new twilio.RestClient(ACCOUNTSID, AUTHTOKEN);
        docs.forEach(function(appointment) {
            // Create options to send the message
            var options = {
                to: "+1" + appointment.phoneNumber,
                from: '+17755834363',
                body: "Just a reminder that you have an appointment coming up  " + moment(appointment.time).calendar() +"."
            };

            // Send the message!
            client.sendMessage(options, function(err, response) {
                if (err) {
                    // Just log it for now
                    console.error(err);
                } else {
                    // Log the last few digits of a phone number
                    var masked = appointment.phoneNumber.substr(0,
                        appointment.phoneNumber.length - 5);
                    masked += '*****';
                    console.log('Message sent to ' + masked);
                }
            });
        });

        // Don't wait on success/failure, just indicate all messages have been
        // queued for delivery
        if (callback) {
          callback.call(this);
        }
    }
};
var Appointment = mongoose.model('appointment', AppointmentSchema);
module.exports = Appointment;

`

My full code can be found here . Any insight into what may be wrong would be greatly appreciated, thanks!

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.