Is anyone using Alloy to post to Gov Notify?

I’m trying to get Alloy to send data out directly to Gov Notify to try and bypass using Alloy emails to the public. I cannot get passed the authorization at present. Has anyone else managed it?

Hi,

You’d somehow 1st need to generate a JWT which won’t be easy without System.Security.Cryptography, then using that value you’d make a request to the service, but you wouldn’t know if the request was successful. The token might have expired since its only valid for 30 seconds.

I’ve attempted in the past with a small Azure Function, then you can post from Alloy to the function. The function could also update an Alloy Item if successful, so you know the notification has been sent.

import azure.functions as func
from notifications_python_client.notifications import NotificationsAPIClient

app = func.FunctionApp()

notifications_client = NotificationsAPIClient('apikey')

async def send_sms(message, number):
    return notifications_client.send_sms_notification(
        phone_number=number,  # required string
        template_id='template_uuid',  # required UUID string
        personalisation={'text': message})     
    
       
@app.route(route="routetocall", auth_level=func.AuthLevel, methods=[func.HttpMethod.POST])
async def notify(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    number = req.params.get('number')
    messagevalue = req.params.get('message')
    
    try:
        req_body = req.get_json()
    except ValueError:
        pass
    else:
        number = req_body.get('number')
        fmsid = req_body.get('message')
        
    if number and fmsid:
        message = f'Hello, Your message is {messagevalue}'
        response = await send_sms(message=message, number=number)
        return func.HttpResponse(f"Done! {response}", status_code=200)
    else:
        return func.HttpResponse(f"Error! ", status_code=400)