Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 
Custom Alert Banner

Send text message using external gateway

kevinmc
Altocumulus
Altocumulus

I have been asked to send a text message by integrating F5 APM with the gov.uk Notify service using their API

 

REST API documentation - GOV.UK Notify (notifications.service.gov.uk)

 

Does anyone know the best way to do this from within an access policy after the "OTP generate" action?

7 REPLIES 7

Hi ,

 

there is a Codeshare from  that you might want to read in order to get some idea how to solve your issue:

https://devcentral.f5.com/s/articles/send-an-one-time-password-otp-via-the-twilio-sms-gateway-1132

 

He uses Twillio, but I think it can be adapted to work with the gov.uk notify service.

The gov.uk seems to provide a nodejs client/library too: https://docs.notifications.service.gov.uk/node.html

 

KR

Daniel 

Yes,   is right. You should be able to adapt the code I've been using for the Twilio gateway to get this working via GOV.UK Notify. If needed, you can send me an temporary API key and templateid and I'll try to get it working.

Thanks for the replies, I will try to adapt your code. I'll need to provision iRulesLX on this Big-IP. I'll come back if I have any problems.

kevinmc
Altocumulus
Altocumulus

You have to replace the content of the default index.js file. This video was a good starting point for me te learn more about iRuleLX:

 

F5 iRules LX - 1. Setting Up /TUTORIAL - YouTube

Thanks Niels, that was a good series of videos so I understand a lot more now. I did run into this issue iRulesLX error: error: 01070711:3: boost::filesystem::status: Permission denied: (f5.com) when I installed the module so had to follow that workaround but I think everything is in place now and I just need to get the code right. I'll post the correct code here if it works or (more likely) I may need to ask another question.

Hi Niels

I have followed your instructions and we have tried to adapt your code using the guidance on gov.uk. I am getting this error:

Rule /Common/ilxplugin_gov_uk/irule_gov_uk <ACCESS_POLICY_AGENT_EVENT>: sendOTP failed for telephoneNumber: +447767826522, ILX failure: ILX timeout. invoked from within "ILX::call $rpc_handle sendOTP $generatedOTP $telephoneNumber "

Can you see what the error could be? I can give you the apiKey and templateId if needed

 

This is my iRule

when ACCESS_POLICY_AGENT_EVENT {
if { [ACCESS::policy agent_id ] eq "gov_uk" } {

set generatedOTP "[ACCESS::session data get session.otp.assigned.val]"
set telephoneNumber "[ACCESS::session data get session.ad.last.attr.extensionAttribute1]"

if {[info exists generatedOTP] && ($generatedOTP eq "")} {
log local0. "Error: generatedOTP variable is empty; no OTP sent for $telephoneNumber."
return
}

if {([info exists telephoneNumber] && $telephoneNumber eq "")} {
log local0. "Error: telephoneNumber variable is empty; no OTP sent for $telephoneNumber."
return
}

set rpc_handle [ILX::init ilxplugin_gov_uk extension_gov_uk]
log local0.info "RPC Handle: $rpc_handle"
if {[ catch { ILX::call $rpc_handle sendOTP $generatedOTP $telephoneNumber } result ] } {
log local0. "sendOTP failed for telephoneNumber: $telephoneNumber, ILX failure: $result"
return
}

log local0. "gov.uk status for user $username ($telephoneNumber): $result"
ACCESS::session data set session.custom.govuk.status $result
}
}

 

index.js

// Import the f5-nodejs module.
var f5 = require('f5-nodejs');

// Create a new rpc server for listening to TCL iRule calls.
var ilx = new f5.ILXServer();

var apiKey = 'x'; // Your API Key
var templateId = 'x'; // Your Template ID

var NotifyClient = require('notifications-node-client').NotifyClient;
var notifyClient = new NotifyClient(apiKey);

ilx.addMethod('sendOTP', function(req, res) {
var generatedOTP = req.params()[0];
var phoneNumber = req.params()[1];
var personalisation = { 'passcode': generatedOTP };
var reference = null;

notifyClient.sendSms(templateId, phoneNumber, {personalisation: personalisation,reference: reference})
.then(response => console.log(response))
.catch(err => console.error(err));
//.then((response) => {return res.reply(response);});
//.catch((response) => {return res.reply(response);});
});

// Start listening for ILX::call and ILX::notify events.
ilx.listen();