0

I'm following the Messagebird docs on sending an SMS through the messagebird API. When I run my app and go to the link in postman, I get no errors and "SUCCESS" is console.logged as well as the reponse. However I never recieve a text. When I go to the SMS logs on the messagebird dashboard there's nothing there except for the test SMS I sent rhough the messagebird dashboard

I've replaced my number for privacy purposes but there was no issue regarding the number being invalid

router.get("/testSMS", (req,res) => {
    messagebird.messages.create({
        originator : 'Movie App',
        recipients : [ '123456778' ],
        body : 'Hello World, I am a text message and I was hatched by Javascript code!'
     }, function (err, response) {
        if (err) {
           console.log("ERROR:");
           console.log(err);
       } else {
           console.log("SUCCESS:");
           console.log(response);
       }
    });
})

Here's my console enter image description here

tza00
  • 97
  • 1
  • 9

1 Answers1

0

This example works for me. If you add your number as a query param does this work for you?

router.get("/test/:phone", (req, res) => {
  const { phone } = req.params;

  // Ensure the phone nubmer follows the E.164 format (https://www.twilio.com/docs/glossary/what-e164)
  if (!/^\+[1-9]{1}[0-9]{3,14}$/.test(phone)) {
    return res.status(400).send("Invalid phone number");
  }

  // Sends a test SMS to the number specified in the request
  messagebird.messages.create(
    {
      originator: "MessageBird",
      recipients: [phone],
      body: "This is a test message from MessageBird",
    },
    (err, response) => {
      if (err) {
        return res.send(err);
      }
      return res.send(response);
    }
  );
});
PCDSandwichMan
  • 1,964
  • 1
  • 12
  • 23
  • nope, still doesn't seem to work for me? this makes me assume its an issue with the number but I don't get any issues with that. When I make the number incorrect I'll get errors though – tza00 Apr 24 '22 at 01:38
  • Do you get an auth error if you deliberately pass in an incorrect token or do you still get a success message? – PCDSandwichMan Apr 24 '22 at 01:45
  • if I deliberately pass in an incorrect number I get an error saying ''no (correct) recipients found. Note: during your test period you can only send messages to your own number'. If I deliberately pass in an incorrect token I get an error saying 'Request not allowed (incorrect access_key)' – tza00 Apr 24 '22 at 01:47
  • Are you using the [E. 164](https://support.twilio.com/hc/article_attachments/360000190288/US_e164.png) format? – PCDSandwichMan Apr 24 '22 at 01:53
  • I'm not sure if that was the issue but I just added a validation check since this is pretty common – PCDSandwichMan Apr 24 '22 at 01:56
  • regarding the E. 164 my phone number doesnt have an area code only a country code, so on my account and the only number it exceppts is (+) (area code) (remaining digits) – tza00 Apr 24 '22 at 01:59
  • What country is the number from? – PCDSandwichMan Apr 24 '22 at 02:01
  • no Ireland, I believe theres area code for landlines? but not mobiles https://telephonedialingcode.com/ireland/ – tza00 Apr 24 '22 at 02:01
  • So you are trying it with this form right? `+353` . For example `015530073` to `+35315530073` – PCDSandwichMan Apr 24 '22 at 02:07
  • yeah thats how I have it. No error comes up with number but just not getting the text. I used the online dashboard that goes through creating the SMS and was able to send one there – tza00 Apr 24 '22 at 02:08
  • Test this with a different number. You can use the burner found on this site if you want: https://freephonenum.com/us/receive-sms/3185456266 – PCDSandwichMan Apr 24 '22 at 02:10
  • I tried that number and got no errors and it loaded success, however it doesnt seem to have sent a text as I cant see anything on that page – tza00 Apr 24 '22 at 02:15
  • It takes a good minute to display just give it a sec – PCDSandwichMan Apr 24 '22 at 02:15
  • This site is a bit faster, try this: https://www.receivesms.co/us-phone-number/3471/ – PCDSandwichMan Apr 24 '22 at 02:18
  • I'm using the free version of the service so I'm pretty sure I can only send to my number. I got this error api error(s): no (correct) recipients found. Note: during your test period you can only send messages to your own number (mynumber) – tza00 Apr 24 '22 at 02:19
  • Oof that makes things a bit harder. I know that Twilio had a few issues with their test accounts not sending messages. I wonder if Messagebird is too. The [A2P](https://support.twilio.com/hc/en-us/articles/1260800720410-What-is-A2P-10DLC-) change messed quite a few things up. – PCDSandwichMan Apr 24 '22 at 02:22
  • 1
    ah thats unfortunate, most likely the case. I'll try contact them and see whats up. thanks anyways! – tza00 Apr 24 '22 at 02:25
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/244220/discussion-between-tza00-and-pcdsandwichman). – tza00 Apr 26 '22 at 11:10