Dynamic User Preferences
Fiscus allows developers to customize and personalize workflows for individual users through dynamic user preferences and context-specific settings. These preferences are essential for adapting workflows based on the unique needs of each user, enabling seamless interaction with different APIs and delivering a tailored experience. Whether you are building a SaaS platform, AI-driven application, or enterprise-grade tool, Dynamic User Preferences provide the flexibility to define user-specific configurations that drive more intelligent and responsive operations.
Core Concepts
- Dynamic Preferences: Custom settings for each user that influence API operations, workflows, and overall application behavior.
- User Context: Contextual data tied to a specific user that can be accessed and modified dynamically, affecting how APIs and workflows operate.
- Contextual Workflows: Workflows that adjust based on user-specific data such as preferred language, timezone, or custom attributes.
- API Customization: Personalized parameters passed to APIs based on dynamic preferences, allowing a more tailored user experience.
Setting and Retrieving Context-Specific Preferences
User preferences and context can be set and retrieved dynamically during the execution of workflows or API operations. This allows applications to react to real-time changes in user behavior or preferences, creating a more fluid and responsive interaction with APIs.
Setting User Preferences
Fiscus allows you to set dynamic preferences that modify how workflows or API calls behave for each individual user. You can set preferences for anything, from preferred languages to specific API behaviors.
- Python
Example: Setting a Dynamic Preference
Imagine a scenario where a user prefers emails in a specific language. You can set this preference dynamically using the following method:
# Setting dynamic preferences for a user
user.set_dynamic_preferences({
'preferred_language': 'en',
'email_format': 'HTML'
})
In this case:
- The
preferred_language
preference will be applied to all workflows and API calls that involve sending emails. - The
email_format
preference specifies that the user prefers HTML-formatted emails rather than plain text.
These preferences can then be used dynamically during API operations to personalize the user's experience.
Example: Setting Multiple Preferences at Once
You can also set multiple dynamic preferences in one go, providing a flexible way to handle user-specific requirements:
# Setting multiple dynamic preferences
user.set_dynamic_preferences({
'preferred_language': 'fr',
'timezone': 'Europe/Paris',
'preferred_currency': 'EUR'
})
In this example, we are setting:
preferred_language
to French.timezone
to Paris time.preferred_currency
to Euros.
These settings will be automatically considered in future API interactions.
Retrieving User Preferences
To personalize API interactions, you often need to retrieve user-specific preferences. Fiscus makes it easy to access these preferences during the execution of workflows.
Example: Retrieving a User's Dynamic Preferences
Once preferences are set, they can be accessed at any time during API operations or workflows:
# Retrieving dynamic preferences
preferences = user.dynamic_preferences
preferred_language = preferences.get('preferred_language')
preferred_currency = preferences.get('preferred_currency')
print(f"User's preferred language is {preferred_language}")
print(f"User's preferred currency is {preferred_currency}")
In this example:
dynamic_preferences
holds all user-specific settings.preferred_language
andpreferred_currency
are retrieved to adapt the workflow or API operation accordingly.
Example: Using Preferences in Workflow Execution
Dynamic preferences can be directly incorporated into API workflows. For example, if you are sending an email or generating a report, the preferences can modify the content or behavior of the API call.
# Using user preferences to customize an API call
email_params = {
'to': 'user@example.com',
'subject': 'Your account details',
'body': 'Here is your report.',
'language': user.dynamic_preferences.get('preferred_language', 'en'),
'format': user.dynamic_preferences.get('email_format', 'TEXT')
}
response = client.execute('Gmail', 'send_email', email_params, user=user)
In this example:
- The
preferred_language
is used to send the email in the user's preferred language. - The
email_format
is retrieved to decide whether the email should be sent in HTML or plain text.
Personalizing Workflows with User Context
In addition to preferences, Fiscus allows developers to set and manage user context, which provides additional customization to workflows and API operations. This context can include various user-specific details like geographical location, account type, or workflow-specific data that should be carried across multiple API calls.
Setting User Context
Fiscus makes it easy to set user-specific context variables that are available across workflows and API calls. This data can be used to personalize operations dynamically.
Example: Setting Context Data
You can store user context data such as geographical location, preferred shipping method, or even session-specific details:
# Setting user context data
user.set_context('location', 'USA')
user.set_context('shipping_method', 'express')
In this case:
location
stores the user’s geographical location.shipping_method
defines the preferred method of shipping.
Example: Retrieving Context Data in a Workflow
When executing an API workflow, context-specific data can be retrieved to make decisions dynamically.
# Retrieving user context data in a workflow
location = user.get_context('location')
shipping_method = user.get_context('shipping_method')
if location == 'USA' and shipping_method == 'express':
# Apply expedited shipping workflow
client.execute('ShippingAPI', 'apply_express_shipping', params, user=user)
else:
# Apply standard shipping workflow
client.execute('ShippingAPI', 'apply_standard_shipping', params, user=user)
In this example:
- The
location
andshipping_method
context data are used to determine which shipping workflow should be applied. apply_express_shipping
orapply_standard_shipping
are conditionally executed based on user context.
Combining Preferences and Context for Advanced Personalization
By combining both dynamic preferences and user context, Fiscus provides a highly flexible environment for creating advanced, personalized workflows.
Example: Customizing Workflows Based on Both Preferences and Context
Consider an example where a user’s preferences (like language and currency) and context (like location and time zone) need to be considered to personalize a workflow.
# Combining preferences and context in a personalized workflow
email_params = {
'to': 'user@example.com',
'subject': 'Your account details',
'body': 'Here is your customized report.',
'language': user.dynamic_preferences.get('preferred_language', 'en'),
'format': user.dynamic_preferences.get('email_format', 'TEXT'),
'currency': user.dynamic_preferences.get('preferred_currency', 'USD'),
'timezone': user.get_context('timezone')
}
response = client.execute('Gmail', 'send_email', email_params, user=user)
In this example:
preferred_language
andemail_format
are used to personalize the email content.preferred_currency
customizes the currency format in the email.timezone
is used to adjust the time references in the email based on the user's context.
Advanced Use Cases for Dynamic Preferences and Context
Use Case 1: Context-Specific API Calls
Some workflows may require context-specific API calls, where different APIs are triggered based on user context.
# Example: Triggering Different APIs Based on Context
location = user.get_context('location')
if location == 'Europe':
client.execute('EuropeShippingAPI', 'create_order', order_params, user=user)
else:
client.execute('GlobalShippingAPI', 'create_order', order_params, user=user)
In this scenario:
- The API for shipping is chosen dynamically based on the user’s
location
context.
Use Case 2: Preferences-Driven Content Personalization
A content personalization platform may use dynamic preferences to determine what type of content to display to the user.
# Example: Using Preferences to Personalize Content Delivery
preferences = user.dynamic_preferences
content_type = preferences.get('content_type', 'default')
if content_type == 'video':
client.execute('ContentAPI', 'fetch_videos', params, user=user)
elif content_type == 'article':
client.execute('ContentAPI', 'fetch_articles', params, user=user)
else:
client.execute('ContentAPI', 'fetch_default_content', params, user=user)
In this example:
- The user’s preferred
content_type
is used to select whether the platform delivers video, article, or default content.
Conclusion
Dynamic user preferences and context-specific settings in Fiscus provide a powerful mechanism for personalizing workflows and API operations. Whether you're building a multi-tenant SaaS platform, managing global users in an enterprise system, or providing highly personalized content in a B2C application, Fiscus enables developers to easily set, retrieve, and utilize user preferences and context data to enhance the user experience.
Key Benefits of Dynamic Preferences and Context:
- Personalized API Workflows: Tailor API interactions based on user preferences such as language, currency, or content format.
- Real-Time Contextual Decisions: Dynamically adapt workflows based on user context (e.g., location, session data, etc.).
- Flexible Preference Management: Set, retrieve, and modify preferences at any time, allowing for real-time customization of workflows.
- Seamless API Customization: Incorporate preferences and context directly into API calls, reducing the need for manual configuration or hardcoding.