-
Notifications
You must be signed in to change notification settings - Fork 1
Tokens Binding
Tokens are key value pairs that can be used for dynamic data purposes. Mainly you want to use tokens for injecting values into email or push notification templates. For template parsing we are using Razor engine which has it's specific syntax (for full syntax overview click here).
There 4 types of tokens used in CodeMash:
- User tokens
- Request tokens
- Project tokens
- Runtime tokens
These are the tokens that you can add yourself in project settings page. The key of the token can only have letters, numbers, dots and underscores and must start with a letter or underscore. Basically a valid C# property name.
Key value is always a string so it can contain any characters.
These are the tokens that you send with a request when making SendEmailNotificationRequest or SendPushNotificationRequest requests. The naming for keys are the same as for user tokens.
These are the tokens that are defined in the system and will be applied automatically. Such tokens are:
Token | Description |
---|---|
Project.Name | The name of the project |
Project.SlugifiedName | The name of the project converted to an URL valid name |
These are the tokens that are set during the process of resolving the tokens. This includes such information like sender and recipient details. Such tokens are:
- Initiator tokens
Token | Description |
---|---|
Initiator.User.FirstName | First name of the user who created the email, push notification |
Initiator.User.LastName | Last name of the user who created the email, push notification |
Initiator.User.FullName | Joined first and last names of the user who created the email, push notification |
Initiator.User.DisplayName | Display name of the user who created the email, push notification |
Initiator.User.Email | Email address of the user who created the email, push notification |
- Receiver tokens
Token | Description |
---|---|
Receiver.User.FirstName | First name of the user who received the email, push notification |
Receiver.User.LastName | Last name of the user who received the email, push notification |
Receiver.User.FullName | Joined first and last names of the user who received the email, push notification |
Receiver.User.DisplayName | Display name of the user who received the email, push notification |
Receiver.User.Email | Email address of the user who received the email, push notification |
- Required tokens for particular actions
Token | Description |
---|---|
ValidationToken | Required for user registration and invitation templates to inject a token for account verification. |
There are more runtime tokens but they are manually binded when doing certain operations in dashboard (such as managing triggers).
For your tokens to be successfully injected you need to add @Model before each of your token so that it would look something like this:
Welcome to project @Model.Project.Name.
That is because all of your tokens are added under the object Model and symbol @ is needed for Razor engine to understand this as a user variable. Unlike Razor syntax where @ symbol doesn't need to be added at certain times, here it must be added at all times.
Templates can also contain other Razor syntax tools not only variables. More complex example shown below:
Welcome to project @Model.Project.Name.
@{
if (@Model.Receiver.User.FirstName == "John")
{
<p>Hello John</p>
}
}
<p style="color: @Model.Colour.Red">Thanks for registering to a project</p>
- If one token is Custom.Token and another token is Custom.Token.Value, the first token will not be injected because the second token makes the first token to become the object without its own value. So in this case first token needs to be renamed. For example it could be Custom.Token.Value1 or Custom.Token1.
- All of the values are of format string so number and other operations will not work on them. You will have to use other Razor syntax tools to convert the value into another type.
-
Getting Started
1.1. Register at CodeMash
1.2. Install CodeMash
1.3. Set up API keys -
Microservices
2.1. Database
2.1.1. Connect
2.1.2. Insert
2.2. Membership
2.2.1. Connect
2.2.2. User Registration
2.2.3. Authentication
2.2.4. User Management
2.3. Files Service
2.2.1. Connect
2.4. Email Notifications
2.2.1. Connect
2.2.1. Emails
2.5. Push Notifications
2.2.1. Connect
2.2.1. Devices
2.2.1. Notifications
2.2.1. Templates
2.6. Scheduler
2.7. Code Service
2.2.1. Connect
2.2.2. Functions
2.8. Logs
2.2.1. Connect
2.2.2. Logs Management -
Other Services
3.1. Project Settings
3.2. Tokens Binding