How to Send SMS from Oracle Database using NowSMS

How to Send SMS from Oracle Database using NowSMS SearchSearch
Author Message
Muhammad Nadeem
New member
Username: Nadeem14375gmailcom

Post Number: 1
Registered: 06-2014
Posted on Tuesday, June 10, 2014 - 08:45 pm:   

hi, I have an application developed with oracle forms and using oracle database 10g.

Can I integrate nowsms and how?

Regards

Muhammad Nadeem
http://star-business-directory.com/
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 4928
Registered: 08-2008
Posted on Tuesday, June 10, 2014 - 10:07 pm:   

Hi,

I don't have any tested examples, but basically you just need to be able to issue an HTTP request from the Oracle side. You send an HTTP request from the Oracle form application to the NowSMS server.

So, on the Oracle side, you need to create a function or procedure that tells NowSMS to send a message. The following link explains the HTTP URL format for sending a text message via NowSMS: http://www.nowsms.com/doc/submitting-sms-messages/sending-sms-text-messages

I have no experience working with Oracle, so I did a web search to find a good example of making an HTTP request from an Oracle form. I liked the example at http://www.inside-oracle-apex.com/sending-sms-to-mobile-phone/, so I modified that code to create an example procedure to send an SMS from an Oracle database form. (This example uses HTTP POST instead of HTTP GET, but NowSMS will work with either format.)

Before attempting to use the example, note the following:

1.) Make sure you can send an SMS from the NowSMS web interface before attempting to use this procedure.

2.) Create an "SMS User" account in NowSMS that will be used by the procedure.

3.) Modify the following lines in the procedure with values appropriate for your NowSMS installation:
 
NowSMS_USERNAME CONSTANT VARCHAR2(40) := 'your_username';
NowSMS_PASSWORD CONSTANT VARCHAR2(40) := 'your_password';
NowSMS_SENDER CONSTANT VARCHAR2(40) := ''; /* set sender address if needed */
NowSMS_SERVER CONSTANT VARCHAR2(80) := 'http://ipaddress:8800/'; /* NowSMS server address */


4.) To send an SMS, call the example procedure with
 
BEGIN
sendSMS('+447777777777','this is a test');
END;


Here is the example procedure, sendSMS:
 
CREATE OR REPLACE PROCEDURE sendSMS
( pRecipient IN VARCHAR2
, pText IN VARCHAR2
)
IS
NowSMS_USERNAME CONSTANT VARCHAR2(40) := 'your_username';
NowSMS_PASSWORD CONSTANT VARCHAR2(40) := 'your_password';
NowSMS_SENDER CONSTANT VARCHAR2(40) := ''; /* set sender address if needed */
NowSMS_SERVER CONSTANT VARCHAR2(80) := 'http://ipaddress:8800/'; /* NowSMS server address */
--
vRequest Utl_Http.req;
vPostText VARCHAR2(500);
vResponse Utl_Http.resp;
vResponseText VARCHAR2(2000);
vErrorText VARCHAR2(200);
BEGIN
----------------------------------------------------------------------------
-- Build text for the post action.
-- For a field description, see
-- http://www.nowsms.com/doc/submitting-sms-messages/url-parameters
----------------------------------------------------------------------------
vPostText :=
'User=' ||Utl_Url.escape(NowSMS_USERNAME, TRUE)||CHR(38)||
'Password=' ||Utl_Url.escape(NowSMS_PASSWORD, TRUE)||CHR(38)||
'Sender=' ||Utl_Url.escape(NowSMS_SENDER, TRUE)||CHR(38)||
'PhoneNumber=' ||Utl_Url.escape(pRecipient, TRUE)||CHR(38)||
'Text=' ||Utl_Url.escape(pText, TRUE);
----------------------------------------------------------------------------
-- Send SMS through the NowSMS SMS service.
----------------------------------------------------------------------------
vRequest := Utl_Http.begin_request
( url => NowSMS_SERVER
, method => 'POST'
);
Utl_Http.set_header
( r => vRequest
, name => 'Content-Type'
, value => 'application/x-www-form-urlencoded'
);
Utl_Http.set_header
( r => vRequest
, name => 'Content-Length'
, value => LENGTH(vPostText)
);
Utl_Http.write_text
( r => vRequest
, data => vPostText
);
vResponse := Utl_Http.get_response(vRequest);
IF vResponse.status_code = '200'
THEN
Utl_Http.read_text(vResponse, vResponseText);
--
IF vResponseText NOT LIKE '%MessageID=%'
THEN
vErrorText := vResponseText;
END IF;
ELSE
vErrorText := 'HTTP status: '||vResponse.status_code||'-'||vResponse.reason_phrase;
END IF;
--
Utl_Http.end_response(vResponse);
--
IF vErrorText IS NOT NULL
THEN
RAISE_APPLICATION_ERROR(-20001, 'Sending SMS failed with '||vErrorText);
END IF;
END sendSMS;


As I said, I have no experience with Oracle development, so there may be errors. If this works, or if you find a solution that works, please share the results.

--
Des
NowSMS Support

Add Your Message Here, or click here to start a new topic.
Post:
Bold text Italics Underline Create a hyperlink Insert a clipart image
Options: Automatically activate URLs in message
Action: