Comments (17)
Awesome idea. Gimme a few hours...
from node-twilio.
That... is why I love GitHub. :-) Cheers!
Please let me know if I can help...! Great library, btw.
from node-twilio.
If you could test when I have a revision done, that'd help a whole lot! I don't really have an awesome testharness app for this, and it'd save me some time getting one together.
from node-twilio.
Latest push contains the change.
twilio/client now accepts an option called express. You can pass in your already-extant express app as that param, and that'll re-use your express app instead of making a new one. You must still pass in your hostanme (for generating the urls to tell Twilio about), and further, you should make sure you know about the basePath variable (the root that autoprovisioned URIs are generated starting from), because they will pollute your express app's routed URIs, and if you try to double them up (really unlikely, unless your app happens to also use /autoprivision/0 or whatever), bad things will happen.
Change committed to master. Let me know if this is acceptable.
from node-twilio.
Did some testing and tinkering... just need to change one thing. You don't want to start the listen if the user is managing the express instance: they'll get an exception.
if(opts.express) {
self.express = opts.express;
}
else {
self.express = express.createServer(
express.logger(),
express.bodyParser()
);
self.express.listen(self.port);
}
Other than that, this works on heroku!
from node-twilio.
This probably isn't the spot for this, but how did you get this working on Heroku? Depending on what method I use (GET or POST) I have different errors on just the initial request from Twilio.
from node-twilio.
What kinds of errors are you getting? Here are a few things to check...
- Are you creating your own express app and passing it in?
- What's the url you're using for your voice url in Twilio? It should be something like http://****/autoprovision/0 unless you've changed the default.
- Is your Heroku related setup correct (i.e. Procfile, package.json) ?
- Are your twilio credentials correct and are you using them when creating a new Twilio client?
- What port is your express listening to? You should be doing something like... var port = process.env.PORT || 3000;
- What port is your TwilioClient using? Try specifying port 80 for the 'port' parameter
from node-twilio.
Thanks for the reply!
- Yes it was something along the lines of: create express, make opts, opts.express = myapp, and then pass opts to TwilioClient
- The url I was using for the voice app was the default one (autoprovision).
- Everything else about Heroku was working except for the routes to TwilioClient
- Yes the same code worked on my machine before moving it to Heroku (and making the address/port changes)
- It was using the method you have
- The issue with supplying 80 as the port is that you need to be root to listen in on 80. Since it seems that if you just use the Heroku port they give you the callback to Twilio includes that port which then modifies your VoiceUrl to include that new port. That port is only accessible once you are behind whatever proxy Heroku has setup. I patched AutoUri (I think) to substitued 80 in instead of the Heroku port, but that didn't seem to accomplish much.
from node-twilio.
In order for this to work on Heroku or similar, the change I outlined above:
if(opts.express) {
self.express = opts.express;
}
else {
self.express = express.createServer(
express.logger(),
express.bodyParser()
);
self.express.listen(self.port);
}
NEEDS to be implemented in the library. Heroku starts the server... attempting to start it again will cause an error.
I can clone and create a merge request, if you like.
from node-twilio.
jwilson... if you're using npm, make the change I have above to line 33 of auto-uri.js and see if that fixes your problems?
from node-twilio.
That was the first change that I did actually. To me it just seems like that once this lib was used as an endpoint with express (I think thats what happens) it stopped serving the node-twilio routes (autoprovision). I haven't yet tried to pass express to node-twilio on amazon (moved my app there for the time being) but I can check it out tonight.
from node-twilio.
Well, I made that change as was able to deploy to Heroku with no problem:
app = express.createServer();
app.use(express.bodyParser());
app.use(express.cookieParser());
var TwilioClient = require('./lib/node-twilio').Client,
Twiml = require('./lib/node-twilio').Twiml,
client = new TwilioClient(config.twilio.sid, config.twilio.token, config.host, {
"express" : app,
"port" : config.port
});
app.get("/" + config.client.name, function(req, res) {
var out = "hello", phone = client.getPhoneNumber('+1' + config.twilio.number);
phone.setup(function() {
phone.sendSms("+1" + config.client.number, out, {}, function(text) {
logger.debug("Text object: " + sys.inspect(text))
});
});
});
app.post("/incoming/sms", function(req, res) {
logger.debug("Received an SMS.");
logger.trace(sys.inspect(req.body));
res.send("<Response><Sms>Thanks!</Sms></Response>");
});
app.listen(process.env.PORT || config.port);
from node-twilio.
Hmm..well I have no idea why mine wasn't working. I will attempt to reproduce the issue this weekend. It just seemed weird that all I had to do was change the port and hostname and it worked on amazon. Anyways, will report back with what I find.
Another edit. How did you configure it so that the callback didn't send the Heroku supplied port back to Twilio? If I used (process.env.PORT || 3000) then when the callback url was create by node-twilio it would have the Heroku port. Twilio would then update my VoiceURL to use the new port...
from node-twilio.
"port" : config.port
I can't get my app to work with this patch. What are you using for config.port
?
from node-twilio.
I had to make one more change to get this to work on Heroku for text messages -
removing self.port from this line: self.baseUri = 'http://' + self.hostname + '/' + self.basePath + '/';
from node-twilio.
(Coffeescript ahead. Pretend it's pseudo-code if you like.)
This'll fix the problem within your app. Send the port like so: (assuming you've defined PORT and the TWILIO constants)
client = new Client TWILIO.ACCOUNT_SID, TWILIO.AUTH_TOKEN, TWILIO.APP_URL,
port: process.env.PORT || PORT
Then follow that with an edit to the global autoUri instance:
autoUri = global.autoUri
autoUri.baseUri = 'http://' + autoUri.hostname + '/' + autoUri.basePath + '/'
from node-twilio.
This library is deprecated in favor of the official library - https://github.com/twilio/twilio-node
from node-twilio.
Related Issues (20)
- Example SMS Send Erroring - Could Not Get Number HOT 4
- Is there any way to have one service listen for multiple numbers? HOT 3
- Twilio hangs up immediately , events not firing HOT 1
- Is there mandatory events with incomingCall? HOT 1
- Modules object is deprecated HOT 2
- Use on dev machines. HOT 3
- undefined request params HOT 2
- Timeouts on heroku HOT 4
- Dial Syntax? HOT 2
- Error 'Could not get number ' HOT 3
- Changing "hostname" to "base_url" HOT 1
- broken again latest express HOT 1
- Setting the URI for a call/text doesn't change the request type HOT 1
- Need more documentation of Twiml.Gather(); HOT 2
- Facilitate Paging? HOT 1
- autoUri is global, and is reported as problem for unit tests like mocha HOT 1
- Is this package still supported? HOT 2
- Documentation link is outdated
- express dependency missing from package.json HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-twilio.