Notifications
The WMS2 Notification microservice can provide notifications about system occurrences, such as creating a plan, changing a plan, changing client data, and more.
Notifications can be sent as:
- SMS
- HTTP-based callback
These notifications are sent to SELLER, ADMIN or SUPER ADMIN users.
Subscription
In the following example, we will see how an ADMIN user can perform a subscription for ORDER-SUBMISSION-SENT system occurrences notification.
This example is about the HTTP-based callback (also known as web hook) for system occurrence notification.
The web hook address is defined for each user: just as a user has his own e-mail address and mobile number, a user also has his own URL for the HTTP callback.
The full list of system occurrence codes is available by consulting the API endpoint api/v1/system-occurence.
For our test we will use webhook.site. Opening webhook.site will display a page with a unique URL: this URL will be used for our callback:
Next, you need to create an ADMIN user and set its URL property to the HTTP address generated by webhook.site. To create an ADMIN user, a SUPER ADMIN token is required:
var createAdminPayload = new
{
Name = name,
Surname = surname,
Email = (name + "." + surname + "@gmail.com").ToLowerInvariant(),
PhoneNumberPrefix = phoneNumberPrefix,
PhoneNumberNumber = phoneNumberNumber,
Url = "https://webhook.site/630f822b-53b5-4de2-afc6-85876c8d4abf", // Please splecify YOUR url
GenderId = genderId,
LanguageId = languageId
};
var payLoadAsString = JsonConvert.SerializeObject(createAdminPayload);
//////////////////////////////////////////////////////////////////////////////////////////////
// Use a SUPER ADMIN token to create an ADMIN user
//////////////////////////////////////////////////////////////////////////////////////////////
using var httpClient = new HttpClient { BaseAddress = new Uri(_configuration["WmsBaseUrl"]) };
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json", 1));
httpClient.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("de-DE", 1));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _configuration["SuperAdminToken"]);
await httpClient.PostAsync($"api/v1/users/admins", new StringContent(payLoadAsString, Encoding.UTF8, "application/json"));
The next step is to register the ADMIN user as the recipient of the notifications. As mentioned above, we are interested in HTTP callback notification:
var systemOccurrences = await httpClient.GetFromJsonAsync<List<SystemOccurenceOutputModel>>("api/v1/system-occurence");
// Get ORDER-SUBMISSION-SENT system notification ID
var systemOccurrenceId = systemOccurrences.First(x = x.Code == "ORDER-SUBMISSION-SENT").Id;
var selectedSystemNotifications = new List<SystemOccurencePreferenceInputModel>();
selectedSystemNotifications.Add(new SystemOccurencePreferenceInputModel
{
Id = systemOccurrenceId,
IsEmailEnabled = false,
IsHttpEnabled = true, // HTTP callback
IsSmsEnabled = false
});
var payLoadAsString = JsonConvert.SerializeObject(selectedSystemNotifications);
await httpClient.PostAsync($"api/v1/system-occurence/user/{adminUserId}", new StringContent(payLoadAsString, Encoding.UTF8, "application/json"));
The subscription is done. Each time a client submits a portfolio order, the ADMIN user will receive a notification.
To test, create a new client by following the Client Regirstration procedure and submit a plan creation request. The result will be the receipt of the following notification: