0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Vonage APIを使ってSMSを送るまで

SMSを送るのにVonage APIを利用してみます。

nodeで実行

npm install @vonage/server-sdk

vonage.js ファイルを作成

const { Vonage } = require('@vonage/server-sdk')

const vonage = new Vonage({
  apiKey: "{ここにapikeyを入力}",
  apiSecret: "{ここにapisecretを入力}"
})
const from = "Vonage APIs"
const to = "{ここに電話番号を入力}"
const text = 'A text message sent using the Vonage SMS API'

async function sendSMS() {
    await vonage.sms.send({to, from, text})
        .then(resp => { console.log('Message sent successfully'); console.log(resp); })
        .catch(err => { console.log('There was an error sending the messages.'); console.error(err); });
}

sendSMS();

公式のここにのってる

これを実行

PS C:\Users\username\Desktop> node vonage.js
Message sent successfully
{
  messages: [
    {
      to: 'phone number',
      'message-id': 'xxxxxx',
      status: '0',
      'remaining-balance': '1.82300000', //残りクレジット
      'message-price': '0.07350000', //料金
      network: 'xxxxxx',
      messageId: 'xxxxxx',
      remainingBalance: '1.82300000',
      messagePrice: '0.07350000'
    }
  ],
  'message-count': '1', //メッセージ件数
  messageCount: '1'
}

本当にSMSが来た、簡単、すげぇ!!

S__22978575.jpg

これなら二段階認証とかも作りやすそう!!
ただ高いかな...為替とかにもよるけどしっかりとクレジットを見ておく必要がありそう!!
以上!!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?