Git Product home page Git Product logo

sms-java-sample's Introduction

Sample app repo for Sinch Getting started

To see a more detailed explanation of how the code will work, visit our SMS getting started page.

Prerequisites

How to run

This template repo allows you to quickly set up a Java Spring boot application to enable you to send and receive SMS via rest commands. It also spins up an ngrok tunnel than you can use to configure your application to receive SMS in the dashboard.

Setup

Open SmsJavaSampleApplication.java and fill in your values. You will find all the below values at https://dashboard.sinch.com/sms/api.

static String SERVICE_PLAN_ID = "";
static String TOKEN = "";
private static String SENDER = ""; 

and run ''' .\gradlew bootRun '''

Sending SMS

The method that handles sending SMS is located at src/main/main/java/com/sinchdemos/smsjavasample/SmsJavaSampleApplication.java and is named sendSMS.

Make a post request with your favorite tool and don't forget to change ToPhonenumber to your own number including + and country code.

Curl

curl --location --request POST 'https://localhost:8080/sms/send' \
--header 'Content-Type: application/json' \
--data-raw '{
    "ToPhonenumber": "+15612600684",
    "Body": "Hello"
}'

PowerShell

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$body = "{
`n    `"ToPhonenumber`": `"+1Your phonenumber`",
`n    `"Body`": `"Hello`"
`n}"
$response = Invoke-RestMethod 'http://localhost:8080/sms/send' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

Receiving SMS

To be able to handle replies to your sent SMS, you need to configure a callback url in the Sinch dashboard. When you start your Java application, an ngrok tunnel is set up that temporarily exposes a website to your application. Open a browser, go to http://localhost:4040/status and copy the URL that ends in ngrok.io. Head over to https://dashboard.sinch.com/sms/api and click the serviceplan id you use for this application. Then click edit where you see Callback URL and paste the url from the ngrok status page. Be sure to click SAVE when you are done.

Note: Every time you restart your application, you will get a new ngrok domain. If you want to set up ngrok manually and keep it running, you can turn off the automatic ngrok by removing compile('io.github.kilmajster:ngrok-spring-boot-starter:0.1') from your gradle file.

sms-java-sample's People

Contributors

alex-sberna avatar jellis72 avatar spacedsweden avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.