Generate OTP
There are some cases when you will need to generate an OTP from a business flow, for example when validating an email account.
The notifications plugins handles both the actual otp code generation and sending the code to the user using a defined notification template.

Define needed Kafka topics

Kafka topic names can be set by using environment variables:
  • KAFKA_TOPIC_OTP_GENERATE_IN
  • KAFKA_TOPIC_OTP_GENERATE_OUT - after the OTP was generated and send to the user, this is the topic used to send the response back to the Engine.
The Engine is listening for messages on topics with names of a certain pattern, make sure to use an outgoing topic name that matches the pattern configured in the Engine.

Request to generate an OTP

Values expected in the request body:
  • processInstanceId: process instance ID
  • templateName: the name of the notification template that is used (this should have been added using the REST API)
  • channel: notification channel: SMS / MAIL / PUSH
  • recipient: notification receiver: email / phone number
  • notification template parameters (ex. clientId): parameters that should be replaced in the notification template

Response from generate OTP

Values expected in the reply body:
  • processInstanceId = process instance ID
  • clientId = the client id
  • channel = notification channel used
  • otpSent = confirmation if the notification was sent: true or false
  • error = error description, if any
Example:
1
{
2
"processInstanceId": 12345,
3
"clientId": "1234567890",
4
"channel": "SMS",
5
"otpSent": true,
6
"error": null
7
}
Copied!

Example: generate an OTP from a business flow

It is important to identify what is the business identifier that you are going to use to validate that OTP, it can be, for example, a users personal identification number.
Step 1: Configure the templates that you want to use:
Make a POST request to NOTIFICATION_URL/api/template with the following body:
1
{
2
"name": "otpMail",
3
"type": "MAIL",
4
"active": true,
5
"language": "en",
6
"subject":"otp for [(${clientId})]",
7
"body": "<!DOCTYPE html><html xmlns:th='<http://www.thymeleaf.org>'><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /></head><body><p>Yay, an otp was generated for you:</p><p th:text='${otpValue}'></p></body></html>",
8
"context": [],
9
"params": [
10
{
11
"key": "clientId",
12
"mandatory": true
13
},
14
{
15
"key": "otpValue",
16
"mandatory": true
17
}
18
]
19
}
Copied!
SMS notification template body:
1
{
2
"name": "otpSMS",
3
"type": "SMS",
4
"strategyType": "SMS",
5
"active": true,
6
"context": [],
7
"language": "en",
8
"subject": null,
9
"body": "OTP [(${otpValue})]",
10
"params": [
11
{
12
"key": "otpValue",
13
"mandatory": true
14
}
15
]
16
}
Copied!
Step 2: Check that the needed topics are configured correctly: the topic used to generate OTP (KAFKA_TOPIC_OTP_GENERATE_IN) and the topic used to receive the response (
KAFKA_TOPIC_OTP_GENERATE_OUT)
Step 3: Use the FLOWX Designer to add a new Kafka send event to the correct node in the process definition
Step 4: Add the proper configuration to the action, the Kafka topic and message to be sent.
Step 5: Add a node to the process definition (for the Kafka receive event)
Step 6: Configure on what key you want to receive the response on the process instance params