SQL Server OLEDB Proc to send WhatsApp Message

CREATE PROCEDURE SendWhatsAppMessage
@AccountSid VARCHAR(50),
@AuthToken VARCHAR(50),
@FromNumber VARCHAR(20),
@ToNumber VARCHAR(20),
@Message VARCHAR(1000)
AS
BEGIN
DECLARE @Url VARCHAR(2000)
DECLARE @PostData VARCHAR(2000)
DECLARE @ResponseText VARCHAR(8000)
DECLARE @WinHttpReq INT

SET @Url = ‘https://api.twilio.com/2010-04-01/Accounts/’ + @AccountSid + ‘//img.intertoons.com/Messages.json’
SET @PostData = ‘From=whatsapp:’ + @FromNumber + ‘&To=whatsapp:’ + @ToNumber + ‘&Body=’ + @Message

EXEC sp_OACreate ‘WinHttp.WinHttpRequest.5.1’, @WinHttpReq OUT;
EXEC sp_OAMethod @WinHttpReq, ‘Open’, NULL, ‘POST’, @Url, ‘false’
EXEC sp_OAMethod @WinHttpReq, ‘SetRequestHeader’, NULL, ‘Content-Type’, ‘application/x-www-form-urlencoded’
EXEC sp_OAMethod @WinHttpReq, ‘SetRequestHeader’, NULL, ‘Authorization’, ‘Basic ‘ + CAST(N” AS XML).value(‘xs:base64Binary(xs:hexBinary(sql:column(“token_bin”)))) AS token
EXEC sp_OAMethod @WinHttpReq, ‘Send’, NULL, @PostData
EXEC sp_OAMethod @WinHttpReq, ‘ResponseText’, @ResponseText OUTPUT

EXEC sp_OADestroy @WinHttpReq;

SELECT @ResponseText
END


Interoons aim at providing electronically intelligent and comprehensive range of digital marketing solutions that exceed customer expectations. We implement revolutionary digital marketing ideas to achieve a common as well as the aggregate growth of the organization. Long-term customer relations and extended support are maintained.

Leave a Reply

Your email address will not be published. Required fields are marked *