Forum Discussion

7 Replies

    • Niels_van_Sluis's avatar
      Niels_van_Sluis
      Icon for MVP rankMVP

      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.

      • kevinmc's avatar
        kevinmc
        Icon for Altocumulus rankAltocumulus

        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's avatar
      kevinmc
      Icon for Altocumulus rankAltocumulus

      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();