After investigating whether GCP's service could replace sending messages with Amazon SMS, Google recommended a third-party service called Twilio, so I tried it.
· Twilio's use of SMS and voice services (https://cloud.google.com/appengine/docs/flexible/nodejs/using-sms-and-voice-services-via-twilio?hl=ja)
Many people don't know what Twilio looks like. Simply put, it's a cloud API service with features such as voice calls, SMS, chat, and video. As a feature **, you can control phone calls, SMS, faxes, etc. with a program **, so I think you should consider it when you want to create a service related to an application or system.
If you're curious, Twilio's partner KDDI has posted more information on the web. https://twilio.kddi-web.com/
To use Twilio, you first need to create an account.
https://twilio.kddi-web.com/
Register for an account by signing up for free at the link above. Follow the instructions on the site to complete the account creation. It's a general procedure, so I don't think it's particularly difficult.
Get the phone number you want to use with your Twilio account. Please note that if you want to use SMS, you need to get ** American phone number ** starting with country code 1 (because Japanese phone number does not support SMS).
Below is the procedure for getting a phone number
You have now obtained your phone number and are ready to use SMS.
Now let's actually send a message using Twilio's Programmable SMS service. The following site (English) was helpful. https://www.twilio.com/docs/sms/quickstart
As shown in the image, the contents are organized by programming language, so I think you should refer to the language that suits your taste. This time I will try with ** Python **.
If you have not installed python in your local environment, you can install it with the following command.
python
pip install python;
Install the library with the following command.
python
pip install twilio;
If pip: command not found </ font> is displayed, execute the following command.
python
easy_install twilio
Reference URL: https://jp.twilio.com/docs/libraries/python
Check the ACCOUNT SID and AUTH TOKEN in the links below. https://jp.twilio.com/console/project/settings
Copy the code below into an editor or notepad.
sms_message.py
# Download the helper library from https://www.twilio.com/docs/python/install
from twilio.rest import Client
# Your Account Sid and Auth Token from twilio.com/console
# DANGER! This is insecure. See http://twil.io/secure
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)
message = client.messages \
.create(
body="Hello from Python!",
from_='+Caller's phone number (including country code)',
to='+Message destination phone number (including country code)'
)
print(message.sid)
When you hit the Python file you just created with the command, a message will be sent.
python send_sms.py
I was able to confirm the message safely.
The above is the flow of the list until sending SMS. I'll summarize the pricing system and Twilio services other than SMS if there is a next time or later.
Recommended Posts