Fireship · @fireship

Send SMS Text Messages with Twilio and Firebase

Uploaded September 13, 2017 · Length 9:17

Send SMS Text Messages with Twilio and Firebase

Summary

send text messages with twilio and firebase in angular app

  • twilio
  • firebase
  • angular
  • text messaging
  • sms
  • cloud functions

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    sending text messages through your app

  2. 0:01

    can bring the user experience to the

  3. 0:03

    next level in this lesson I have an

  4. 0:05

    angular app where users can order a

  5. 0:06

    pizza for delivery my goal is to update

  6. 0:09

    the users with a text message every time

  7. 0:11

    their order status changes so when the

  8. 0:13

    pizza goes from cooking to on its way

  9. 0:15

    that user gets notified directly in

  10. 0:17

    their phone to handle the text messaging

  11. 0:19

    we're going to use an API called Twilio

  12. 0:21

    combined with firebase cloud functions

  13. 0:23

    let's start by learning a little bit

  14. 0:25

    more about Twilio from their promo video

  15. 0:27

    Twilio is a global communications

  16. 0:30

    platform for developers with our API and

  17. 0:32

    a few lines of code you can add

  18. 0:34

    messaging voice and video to your

  19. 0:36

    applications in the programming language

  20. 0:38

    you already use so after we sign up for

  21. 0:40

    a Twilio account they're going to assign

  22. 0:42

    us a phone number and we can use that

  23. 0:44

    phone number to send text messages to

  24. 0:45

    our users you can sign up without a

  25. 0:47

    credit card and they'll give you a 15

  26. 0:49

    dollar credit to experiment with the API

  27. 0:51

    so once you've signed up make note of

  28. 0:54

    your phone number as well as your API

  29. 0:56

    keys which we're going to use to build

  30. 0:58

    the firebase cloud function but before

  31. 1:00

    we get to that point we're first going

  32. 1:01

    to build the angular component for the

  33. 1:03

    front-end so i've generated a new

  34. 1:05

    component called pizza status and it's

  35. 1:07

    going to use the reactive forms module

  36. 1:09

    so we need to make sure to add that to

  37. 1:11

    the import section in our ng module

  38. 1:13

    we're using a reactive form because we

  39. 1:16

    need to validate the phone number

  40. 1:17

    carefully when we send it to Twilio it

  41. 1:19

    needs to be an e 164 format which is a

  42. 1:22

    string that looks like this the country

  43. 1:24

    code with a plus sign followed by at the

  44. 1:26

    full ten digit phone number so let's see

  45. 1:28

    how we can make this possible in the

  46. 1:30

    pizza status component we are going to

  47. 1:32

    break the phone number down into four

  48. 1:33

    different form inputs and then when we

  49. 1:35

    send that data back to firebase it's

  50. 1:37

    going to be the fully formatted II 1 64

  51. 1:40

    string and for this lesson in firebase I

  52. 1:42

    just have a single test order in there

  53. 1:44

    to simulate how this could work in the

  54. 1:47

    component itself we'll first import the

  55. 1:50

    angularfire database as well as the

  56. 1:52

    reactive form parts that we need then

  57. 1:55

    we'll set a variable for the form itself

  58. 1:57

    and set that to the type of form group

  59. 1:59

    and then order we'll represent the data