Can't receive SMS message with Twilio trial account - express

I have a small project (Express) using a Twilio trial account to send an SMS message to my phone number. But when I use my own message to replace the example string, I can't receive the SMS anymore.
This is what I tried:
Verified my own number, so the Twilio phone number can send SMS messages to my own phone number.
Verified the token and sid are the live credentials, not the testing one.
Check the SMS Log, and the status of all messages are sent. But again, I don't receive anything.
Used postman to verify the route if it is working properly. And yes, it did.
This is my code for the route to call the function to send the SMS
router.post("/contacts/sms", authorization, async (req, res) => {
try {
const { phone, message } = req.body;
**sendSms(phone, message);**
res.status(201).send({
message:
"Account created successfully, kindly check your phone to activate your account!",
});
} catch (error) {
res.status(500).send("Server error");
}
});
This is the SMS function
require("dotenv").config();
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const sendSms = (phone, message) => {
const client = require("twilio")(accountSid, authToken);
client.messages
.create({
body: message,
from: process.env.TWILIO_PHONE_NUMBER,
to: phone,
})
.then((message) => console.log(message.sid));
};
module.exports = sendSms;

I have answered a similar question, you might wanna have a look at that
https://stackoverflow.com/a/71912348/17503984
The problem might be since your Twilio phone number and the number you are sending are from different nationalities, communication problems arise due to the international SMS service

Related

Supabase Twilio Phone Auth

I am building a react native app using Supabase with phone auth on Android emulator.
I have set my twilio and Supabase up, but when I call supabase.auth.signUp(), it does not send a OTP to my phone number.
This is my code:
async function signInWithPhoneNumber() {
let { data, error } = await supabase.auth.signUp(
{ phone: '+61 xxx xxx xxx',
password: 'some-password' }) setConfirm(data);
console.log(data)
if (error) {
console.log('error')
return } }
And I just have a button that calls this function. The 'xxx xxx xxx' is a placeholder for my actual number. I tried using the provided Twilio phone number as well but to no success. My twilio account is working well, as i was able to send a message from Twilio to my real phone. And I correctly put in the phone auth details for Supabase.
My log for the 'data' gives me: {"session": null, "user": null}
And if i was to log the actual error, it gives me: [AuthRetryableFetchError: Network request failed]
Anyone know the issue?
Thanks!
I don't think you can use phone authentication with password: only OTP. Have you tried the following:
await supabase.auth.signInWithOtp({
phone: '+61xxxxxxxxx',
})
await supabase.auth.verifyOtp({
phone: '+61xxxxxxxxx',
token: 'xxxxxx',
type: 'sms'
})
see also:
https://supabase.com/docs/reference/javascript/auth-signinwithotp
https://supabase.com/docs/reference/javascript/auth-verifyotp

Give web app permanent control of google email

I recently got a domain from Google Domain and it provides professional emails for the domain. So, I made a support#domain email to send and receive emails. Right now, I built a web app that will use this email to send email-verification to new users who sign up.
I got the code working, however, I used OAuth2.0 from Google to allow the web app to sign into the support email. This causes the Access token to expire and forces me to into my .env file and replace BOTH tokens. How tedious! If I were to publish this web app, I can't just go into my heroku vars and replace the tokens every hour. Thats extremely impractical.
I looked into service accounts by google, but they seem to STILL need OAuth anyways as a 3 legged OAuth. As I am using Express.js, I wanted to know if there was a way to set the tokens and be done with it permanently. Essentially giving the web app permanent control of the google account. What do I do? And what do I use? All advice is greatly appreciated.
Code for sending email verification:
const nodemailer = require("nodemailer")
const dotenv = require("dotenv")
const {generateVerifyToken} = require("./auth")
const { print } = require("#AlecRuin/color-logger")
dotenv.config()
let transporter = nodemailer.createTransport({
service:"gmail",
auth: {
type: 'OAuth2',
user: process.env.EMAIL,
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
refreshToken: process.env.REFRESH_TOKEN,
accessToken: process.env.ACCESS_TOKEN
}
})
module.exports= async function(email){
try {
let mailOptions={
from: "support#domain.us",
to:email,
subject:"Verify your email",
text:`
Thank you for signing up with redacted!!
To verify your email (and make sure you're not some kind of annoying bot), simply follow this link:
${process.env.NODE_ENV === "production"?"www.redacted.com":"localhost:3001"}/api/user/verify/?token=${generateVerifyToken(email)}
`
}
print("sending email",new Error,{isClient:false})
transporter.sendMail(mailOptions,(err,data)=>{
if (err){
console.error(err);
return err
}else{
print("Email sent!",new Error,{isClient:false})
return true
}
})
} catch (error) {
print(error,new Error, {isClient:true,severity:4})
return error
}
}

Does Stripe still allow pre-filling for express accounts? If yes, what is syntax to pass things like email, first name, business name etc

image of initial landing screen where i also want mobile phone pre-filled
Have been following some online tutorials on creating a Stripe Marketplace, have it all configured however I'm having trouble passing details i have collected on a user, ie email as best example, and then having that be pre-filled when a new vendor on my marketplace goes through the Stripe Connect Express onboarding process.
Any help would be great, particularly on how to pass these details in the accountLink that is being sent.
export const makeSeller = async (req, res) => {
try {
// 1. find user from db
const seller = await Seller.findById(req.user._id).exec();
// 2. if user dont have stripe_account_id yet, then create new
if (!seller.stripe_account_id) {
const account = await stripe.accounts.create({ type: 'express' });
// console.log('ACCOUNT => ', account.id)
seller.stripe_account_id = account.id;
seller.save();
}
// 3. create account link based on account id (for frontend to complete onboarding)
let accountLink = await stripe.accountLinks.create({
account: seller.stripe_account_id,
refresh_url: process.env.STRIPE_REDIRECT_URL,
return_url: process.env.STRIPE_REDIRECT_URL,
type: 'account_onboarding',
});
console.log('ACCOUNT LINK', accountLink);
// 4. pre-fill any info such as email (optional), then send url resposne to frontend
accountLink = Object.assign(accountLink, {
'stripe_user[email]': seller.email,
});
// 5. then send the account link as response to fronend
res.send(`${accountLink.url}?${queryString.stringify(accountLink)}`);
} catch (err) {
console.log('MAKE SELLER ERR ', err);
}
};
Stripe allows any of the fields on an Account object to be prefilled! The place to prefill this info is in the stripe.accounts.create call before creating the AccountLinks object, if you prefill the information in the Account object, it will not be collected in the onboarding flow[1].
const account = await stripe.accounts.create({ type: 'express', email: 'vendor#example.com' });
Check out the API doc section on creating an Account object for info on how to populate specific fields[2].
[1] https://stripe.com/docs/connect/express-accounts#create-account
[2] https://stripe.com/docs/api/accounts/create

nodejs robinhood api login

I am trying to login to the robinhood API, I turned 2fa and sms off in the app but am still getting an error does this look correct below or is robinhood just slow at updating when 2fa is turned off.
var credentials = {
username: '*****',
password: '*****'
};
var Robinhood = require('robinhood')(credentials, function(){
console.log(Robinhood.auth_token());
// <authenticated alphanumeric token>
})
the error
Error: token not found {"statusCode":400,"body":{"detail":"Request blocked, challenge type required.","accept_challenge_types":{"sms":"SMS"}},"headers":{"date":"Mon, 24 May 2021 22:44:07 GMT","content-type":"application/json","content-length":"93","connection":"close","server":"openresty","allow":"POST, OPTIONS","x-robinhood-api-version":"0.0.0","content-security-policy":"default-src 'none'","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","x-xss-protection":"1; mode=block","access-control-allow-origin":"https://robinhood.com","vary":"Origin","trace-uuid":"56ccb9cc-8bca-4dbd-be6f-4a6d86171354"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"api.robinhood.com","port":443,"hostname":"api.robinhood.com","hash":null,"search":null,"query":null,"pathname":"/oauth2/token/","path":"/oauth2/token/","href":"https://api.robinhood.com/oauth2/token/"},"method":"POST","headers":{"Host":"api.robinhood.com","Accept":"*/*","Accept-Encoding":"gzip, deflate","Referer":"https://robinhood.com/","Origin":"https://robinhood.com","content-type":"application/x-www-form-urlencoded","content-length":214}}}
Robinhood recently required 2fa to be enabeld if using the api. It is mentioned in the detail of the request body.
"detail":"Request blocked, challenge type required.","accept_challenge_types":{"sms":"SMS"}}
Go ahead and turn it on and then you can access the api with this snippet
let Robinhood = require('robinhood')(credentials, function(data) {
if (data && data.mfa_required) {
var mfa_code = ""; //Notice this is blank.
Robinhood.set_mfa_code(mfa_code, () => {
console.log(Robinhood.auth_token());
Robinhood.positions((error, response, body) => {
console.log(body);
})
})
}
})
Once you make a request you'll get an error, but the 2fa challenge will be sent to whatever you set your account with. Once you received the 2fa code, set the mfa_code and re-run the snippet. Once you ran the snippet again with a valid 2fa code, then you've successfully logged in. Copy the authorization token and you can use that without the need of going through 2fa again for i believe 24 hrs

How to Handle push notification when sent to multiple device but some them are failed

I want to send fcm push notifications to android and ios app. I am using this code to send
let message = {
registration_ids: firebaseId, // this is the array of tokens
collapse_key: 'something',
data: {
type: data.type,
title: data.title,
body : data.body,
notificationId: something
},
};
fcm.send(message, (err, response) => {
if (err) {
console.log(err);
resolve(false);
} else {
console.log("Notification Android Sent Successfully");
console.log(response);
}
});
Now what I want if some notifications are failed then I want to send them SMS. but I got a response like this form the fcm server in case of success or failure.
Notification Android Sent Successfully
{"multicast_id":7535512435227354255,"success":2,"failure":1,"canonical_ids":0,"results":[{"message_id":"0:1610622370449056%d0bd483c86f03759"},{"message_id":"0:1610622370449058%d0bd483c86f03759"},{"error":"InvalidRegistration"}]}
now how will I know which device did not get the notification as we can see there 1 failure from 3 device
so i can send SMS to that device
The results in the response you get contains the result for each token, in the same order in which you specified them,
So in your example, the message was successfully sent to the first two tokens, while the third token was unknown. You'll want to remove that last token from your database to prevent trying to send messages to it in the future.