N
Novu6mo ago
Tam

Step condition by comparing a payload field with a subscriber field

Hi everyone, I'm trying to add a step condition to only perform a step if a payload field value matches a subscriberId. The condition creation UI only allows comparing with a literal not a system variable. What should I do to achieve that. Thank you in advance!
3 Replies
Ask Inkeep
Ask Inkeep6mo ago
Hi @Tam, I'm an AI assistant for Novu. While a team member reviews this question, I'll see if I can find relevant sources for your question. ----------------------------- While I generate an answer, here are some sources that might be helpful: * Step Conditions * Ruby quickstart * General * .NET ----------------------------- Answer Currently, the Novu UI for creating step conditions doesn't support directly comparing a payload field with a system variable like subscriberId directly in the UI. However, you can achieve this functionality by using a custom logic setup in your backend before sending the payload to Novu. You can preprocess the data in your server-side application to check if the payload field matches the subscriberId, and then trigger the Novu notification based on the outcome of that check. Here’s an example of how you could implement this in a server-side script (assuming you're using Node.js):
const novu = require('novu');

// Assuming `payloadData` and `subscriberId` are obtained earlier in your code
if (payloadData.field === subscriberId) {
const novuClient = new novu.Client('<NOVU_API_KEY>');

novuClient.trigger({
event: '<YOUR_EVENT_IDENTIFIER>',
subscriberId: subscriberId,
payload: payloadData
});
}
const novu = require('novu');

// Assuming `payloadData` and `subscriberId` are obtained earlier in your code
if (payloadData.field === subscriberId) {
const novuClient = new novu.Client('<NOVU_API_KEY>');

novuClient.trigger({
event: '<YOUR_EVENT_IDENTIFIER>',
subscriberId: subscriberId,
payload: payloadData
});
}
This script checks if the payload field matches the subscriberId and triggers the notification only if they match. Replace <NOVU_API_KEY> and <YOUR_EVENT_IDENTIFIER> with your actual Novu API key and event identifier. This approach requires handling the condition on your side before utilizing Novu's notification services. For more direct support with dynamic conditions involving system variables, consider reaching out to Novu's support or the community for feature requests or updates on this functionality.
Tam
TamOP6mo ago
Thank you, got it. Actually the answer is in the doc screenshot
No description
Ask Inkeep
Ask Inkeep6mo ago
Glad I could be helpful. Feel free to create a new thread with any new questions you may have.
Want results from more Discord servers?
Add your server