3 Easy steps to help increase the value of your website with AT&T Messaging
Guest post by Junaid Ali, AT&T Technology Development; API Platforms
With AT&T’s In-App Messaging API, developers can easily incorporate text communication capabilities between their websites and mobile phone users. It only takes five minutes to add this functionaility on gaming websites, shopping apps, online reservation and more.
Let’s start by implementing the feature on a simple website where the user can send/receive messages from his or her device. Once the site is up and running, we will look at the actual code and how it can be re-purposed to suit end user requirements as needed.
Install NetBeans with GlassFish. You will need to have JDK 7 or later installed. You can install it by clicking this link. Download source code for sample apps from the github repository. Open NetBeans IDE and import the sample app after unziping the sample apps in a directory (you will find these unzipped under “Code”).
Open the resource “application.properties under src/main/resources”
Step 1 – Create a Free Developer Account at developer.att.com
This can easily be upgraded to a Full Access Account.
Step 2 – Once an Account is Created, Click on “My Apps,” and “Create an app” Links.
Make sure you select IMMN and MIM in scopes.
A listener is provided under /oAuth in the code for an oAuth loopback (we will dig deeper into that later). Ensure the oAuth URL in the app matches the correct host, port, and the default context path.
For example, I have deployed the code on host “localhost” at port 12709 with the default context path as /app1. Hence the oAuth Redirect URL while submitting the app would be http://localhost:12709/app1/oauth (you can edit this in the ATT App later, as well).
Step 3 – Get App Keys
Once the app is created, Plug in the App Key and secret and the URL under “redirectUri” found in Application.properties beneath src/main/resources
Make sure the FQDN’s points to the correct URL where the app is deployed (I have deployed the app on a GlassFish server at port 12709 under /app1).
Once the application has been setup correctly, you are all set to send and receive messages on behalf of the user from the website.
That’s it. You’re now ready to have your website send and receive SMS messages.
Let’s Get into the Code and See How that Really Happens
The code example below loosely follows a simple MVC architecture. All UI elements have been added to a single file “immn.jsp” and the servlet mapping is defined in web.xml.
The controller classes are used to serve user inputs.
The bulk of the actual code which interacts with the API is defined under “ImmnService.java”
The “SendMsgController” that sends the message in the current example could be repurposed to set up a group chat for example.
Let us assume there is a database with a mapping between a user and groups. The mapping is defined below:
The code in “index.jsp” would need to be modified to accept data from “Table 1” and populate a drop-down instead of a text area to input the phone number.
On the controller side, the file “SendMessageController” would need to be modified to get the Group Name instead of a phone number.
The controller would then select the Group ID mapped to a particular MSISDN and Group name, and then fetch the phone numbers associated with that group.
Once the numbers are added to an array, the controller can call IMMNService. sendMessage(address, msg, subject, group (Boolean indicating message visibility and reply options).
So there you have it; three easy steps to integrate SMS messaging into any website or mobile app. For more details on how to use the API refer to the documentation. For more efficient push notification services to a developer hosted server, refer to our Webhooks API.