# Receive an incoming SMS Message Note: Before you can get started, you need the following already set up: - - [The latest version of .Net Core with **Long Term Support**](https://dotnet.microsoft.com/download) and a familiarity with how to create a new MVC app. - [ngrok](https://ngrok.com/). You'll use ngrok to open a tunnel to your local server. Learn how to handle incoming SMS messages in a .Net Core MVC application with the Sinch SMS API. Steps: 1. [Set up](#set-up-your-net-core-application) your .NET Core application 2. [Configure](#configure-your-callback-url) your Callback URL 3. [Test](#send-your-sms-message) the application ## Set up your .Net Core application 1. Create a new folder where you want your app project. Then, open a terminal or command prompt to that location. 2. Create a new .Net Core MVC app with the following command: ```shell dotnet new mvc ``` 3. Add the `Newtonsoft.Json` nuget package: ```shell dotnet add package Newtonsoft.Json ``` ### Modify your application The controller does the work of handling the SMS. It receives the incoming SMS from Sinch's servers and performs an action in response. In this tutorial, it simply replies to your incoming message, but you can add any business logic you want. The controller uses two other classes, `InboundSMS` for the incoming message and `SMS` which contains the function to send an SMS. 1. In the Controllers folder of your project, create a new file named `InboundController.cs`. 2. Populate that file with the "Handle receiving an SMS message" code found on this page. 3. Replace the following values for these parameters with your values: | Parameter | Your value | | --- | --- | | `YOUR_servicePlanId` | The API token found on your Sinch [dashboard](https://dashboard.sinch.com/sms/api/rest). | | `YOUR_API_token` | The service plan ID found on your Sinch [dashboard](https://dashboard.sinch.com/sms/api/rest). Click `Show` to reveal your API token. | Double check that the region is correct on your base URL. Learn more about [regional options here](/docs/sms/api-reference#base-url). 4. Save the file. ### Build your project Before executing your code, you must first compile your application. Execute the following command: ```shell dotnet build ``` ### Start your web server and set up a tunnel 1. Start the server by executing the following command: ```shell dotnet run ``` By default, your web server is started on port 5001. 2. Open a tunnel to the server you just set up. We are using [ngrok](https://ngrok.com/) for this. If you don't have ngrok installed already, install it with the following command: ```shell npm install ngrok -g ``` 3. Open a terminal or command prompt and enter: ```shell ngrok http https://localhost:5001 ``` You will see a screen like the following. ![ngrok screenshot](/assets/ngrok.135751fc8aa7c936230a2a88bff2263644a1d1737263acc00294006a34b0f60b.c6cba068.png) 4. On the highlighed "Forwarding" line, copy the address ending in `.ngrok.io` and add `/Inbound/ReplyToInbound` to the end of it. ### Configure your Callback URL 1. To configure a callback URL for your Sinch account, login to your [dashboard](https://dashboard.sinch.com/sms/api/rest). 2. Click on the service plan ID link and edit the Callback URL field with the ngrok.io domain URL from the previous section. ## Send your SMS message Now send an SMS message to your Sinch number from your mobile phone and you will get an automatic reply. ## Next steps The code you used in the `Inbound.cs` file sends a POST request to the Sinch API `/batches` endpoint to send the SMS message. - Explore the [API specification](/docs/sms/api-reference/) to test more endpoints. ## Additional resources - Click [here to read more about the batches endpoint](/docs/sms/api-reference/sms/batches).