-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: url.URL is not a constructor #577
Comments
After some digging and help, looks like this is related to defunctzombie/node-url#37 At a high-level, this repo should not be used in a client-side (React) app. Communicating with Twilio APIs requires auth which would be exposed to the end-user. Blog about this and how to re-architect: https://www.twilio.com/blog/send-an-sms-react-twilio |
I think there are significant valid use cases wherein someone might want to run twillio-node on a react frontend. For example, in an electron app where the user is also the owner of the twillio account (or are from the same organisation). This is my use case. It seems that, apart from this URL class issue, nothing else would stop twillio to work on the frontend. Is there any workaround ? How could one get access to the URL class native to node, but in a browser? |
You can use the REST HTTP API directly using axios for http requests, and qs.stringify to get the parameters encoded properly:
|
am having the same issue with angular, any one with a satisfactory solution |
Did you see my approach above? It's how you make requests without needing to use the twilio-node library. |
May you share the whole script so as to easily follow up with your code |
The whole thing is there. message is a string of what you want to send. from is the twilio number you are using. to is the destination number. sid and token are the twilio authentication details. You will need to import axios and import qs: axios = require('axios') This lets you send SMS via Twilio from a browser. It's live in Uganda right now. ;-) |
The challenge am having is that the api recognizes my phone number as
invalid even when I use E.164 format
…On Wed, May 19, 2021 at 10:43 PM Mike McKay ***@***.***> wrote:
May you share the whole script so as to easily follow up with your code
The whole thing is there. message is a string of what you want to send.
from is the twilio number you are using. to is the destination number. sid
and token are the twilio authentication details. You will need to import
axios and import qs:
axios = require('axios')
qs = require('qs')
This lets you send SMS via Twilio from a browser. It's live in Uganda
right now. ;-)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#577 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALX4NJRBPOQ45LN7JKUPQHLTOQIHRANCNFSM4NNJP7ZQ>
.
|
What's the error code from Twilio?
On Wed, May 19, 2021 at 9:47 PM Tumusiime Barnabus ***@***.***>
wrote:
… The challenge am having is that the api recognizes my phone number as
invalid even when I use E.164 format
On Wed, May 19, 2021 at 10:43 PM Mike McKay ***@***.***>
wrote:
> May you share the whole script so as to easily follow up with your code
>
> The whole thing is there. message is a string of what you want to send.
> from is the twilio number you are using. to is the destination number.
sid
> and token are the twilio authentication details. You will need to import
> axios and import qs:
>
> axios = require('axios')
> qs = require('qs')
>
> This lets you send SMS via Twilio from a browser. It's live in Uganda
> right now. ;-)
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#577 (comment)
>,
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/ALX4NJRBPOQ45LN7JKUPQHLTOQIHRANCNFSM4NNJP7ZQ
>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#577 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAC5342JT4XMIFR66JKMKDTOQIUFANCNFSM4NNJP7ZQ>
.
|
21211
On Wed, May 19, 2021 at 10:49 PM Mike McKay ***@***.***>
wrote:
… What's the error code from Twilio?
On Wed, May 19, 2021 at 9:47 PM Tumusiime Barnabus ***@***.***>
wrote:
> The challenge am having is that the api recognizes my phone number as
> invalid even when I use E.164 format
> On Wed, May 19, 2021 at 10:43 PM Mike McKay ***@***.***>
> wrote:
>
> > May you share the whole script so as to easily follow up with your code
> >
> > The whole thing is there. message is a string of what you want to send.
> > from is the twilio number you are using. to is the destination number.
> sid
> > and token are the twilio authentication details. You will need to
import
> > axios and import qs:
> >
> > axios = require('axios')
> > qs = require('qs')
> >
> > This lets you send SMS via Twilio from a browser. It's live in Uganda
> > right now. ;-)
> >
> > —
> > You are receiving this because you commented.
> > Reply to this email directly, view it on GitHub
> > <
#577 (comment)
> >,
> > or unsubscribe
> > <
>
https://github.com/notifications/unsubscribe-auth/ALX4NJRBPOQ45LN7JKUPQHLTOQIHRANCNFSM4NNJP7ZQ
> >
> > .
> >
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#577 (comment)
>,
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/AAAC5342JT4XMIFR66JKMKDTOQIUFANCNFSM4NNJP7ZQ
>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#577 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALX4NJQBSY2LPWP4OPF4QWTTOQI5BANCNFSM4NNJP7ZQ>
.
|
Any suggestions?
On Wed, May 19, 2021 at 10:53 PM Tumusiime Barnabus <
***@***.***> wrote:
… 21211
On Wed, May 19, 2021 at 10:49 PM Mike McKay ***@***.***>
wrote:
> What's the error code from Twilio?
>
> On Wed, May 19, 2021 at 9:47 PM Tumusiime Barnabus ***@***.***>
> wrote:
>
> > The challenge am having is that the api recognizes my phone number as
> > invalid even when I use E.164 format
> > On Wed, May 19, 2021 at 10:43 PM Mike McKay ***@***.***>
> > wrote:
> >
> > > May you share the whole script so as to easily follow up with your
> code
> > >
> > > The whole thing is there. message is a string of what you want to
> send.
> > > from is the twilio number you are using. to is the destination number.
> > sid
> > > and token are the twilio authentication details. You will need to
> import
> > > axios and import qs:
> > >
> > > axios = require('axios')
> > > qs = require('qs')
> > >
> > > This lets you send SMS via Twilio from a browser. It's live in Uganda
> > > right now. ;-)
> > >
> > > —
> > > You are receiving this because you commented.
> > > Reply to this email directly, view it on GitHub
> > > <
> #577 (comment)
> > >,
> > > or unsubscribe
> > > <
> >
> https://github.com/notifications/unsubscribe-auth/ALX4NJRBPOQ45LN7JKUPQHLTOQIHRANCNFSM4NNJP7ZQ
> > >
> > > .
> > >
> >
> > —
> > You are receiving this because you commented.
> > Reply to this email directly, view it on GitHub
> > <
> #577 (comment)>,
> > or unsubscribe
> > <
> https://github.com/notifications/unsubscribe-auth/AAAC5342JT4XMIFR66JKMKDTOQIUFANCNFSM4NNJP7ZQ
> >
> > .
> >
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#577 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ALX4NJQBSY2LPWP4OPF4QWTTOQI5BANCNFSM4NNJP7ZQ>
> .
>
|
I assume you have read this in detail:
https://www.twilio.com/docs/api/errors/21211
(sending/receiving to the same number perhaps?)
Does it work for other numbers? I did find that there are some Ugandan
phone numbers that Twilio won't send to, apparently because they are on a
spam list, which seemed really odd since we were messaging teachers.
On Wed, May 19, 2021 at 10:01 PM Tumusiime Barnabus <
***@***.***> wrote:
… Any suggestions?
On Wed, May 19, 2021 at 10:53 PM Tumusiime Barnabus <
***@***.***> wrote:
> 21211
>
> On Wed, May 19, 2021 at 10:49 PM Mike McKay ***@***.***>
> wrote:
>
>> What's the error code from Twilio?
>>
>> On Wed, May 19, 2021 at 9:47 PM Tumusiime Barnabus ***@***.***>
>> wrote:
>>
>> > The challenge am having is that the api recognizes my phone number as
>> > invalid even when I use E.164 format
>> > On Wed, May 19, 2021 at 10:43 PM Mike McKay ***@***.***>
>> > wrote:
>> >
>> > > May you share the whole script so as to easily follow up with your
>> code
>> > >
>> > > The whole thing is there. message is a string of what you want to
>> send.
>> > > from is the twilio number you are using. to is the destination
number.
>> > sid
>> > > and token are the twilio authentication details. You will need to
>> import
>> > > axios and import qs:
>> > >
>> > > axios = require('axios')
>> > > qs = require('qs')
>> > >
>> > > This lets you send SMS via Twilio from a browser. It's live in
Uganda
>> > > right now. ;-)
>> > >
>> > > —
>> > > You are receiving this because you commented.
>> > > Reply to this email directly, view it on GitHub
>> > > <
>> #577 (comment)
>> > >,
>> > > or unsubscribe
>> > > <
>> >
>>
https://github.com/notifications/unsubscribe-auth/ALX4NJRBPOQ45LN7JKUPQHLTOQIHRANCNFSM4NNJP7ZQ
>> > >
>> > > .
>> > >
>> >
>> > —
>> > You are receiving this because you commented.
>> > Reply to this email directly, view it on GitHub
>> > <
>> #577 (comment)
>,
>> > or unsubscribe
>> > <
>>
https://github.com/notifications/unsubscribe-auth/AAAC5342JT4XMIFR66JKMKDTOQIUFANCNFSM4NNJP7ZQ
>> >
>> > .
>> >
>>
>> —
>> You are receiving this because you commented.
>> Reply to this email directly, view it on GitHub
>> <
#577 (comment)>,
>> or unsubscribe
>> <
https://github.com/notifications/unsubscribe-auth/ALX4NJQBSY2LPWP4OPF4QWTTOQI5BANCNFSM4NNJP7ZQ
>
>> .
>>
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#577 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAC5325GZ7NO46PKIMG3SLTOQKJDANCNFSM4NNJP7ZQ>
.
|
I found an ugly workaround, hope it helps
Only once, before any usage of any intercept / request or any url dependencies related. |
tested with angular 14 SSR, you should lazy load it to prevent it leak to override global namespace URL of nodejs (mention here muaz-khan/RecordRTC#666) let z;
let moduleTw;
await this.ngZone.run(async () => {
// https://stackoverflow.com/a/58859327/5748537
moduleTw = await import('twilio');
z = (moduleTw as any).default;
});
|
Issue Summary
I am using latest version of this library 3.44.0. (I see from the npm version log. it's just a day ago!) and having the following error.
TypeError: url.URL is not a constructor when I try to send message. the code is copied from doc. https://www.twilio.com/docs/sms/quickstart/node
Steps to Reproduce
Code Snippet
Exception/Log
Technical details:
The text was updated successfully, but these errors were encountered: