How to create messages with the Echo Assistant?
In this article, we focus on the possibilities to create messages for the final user. These messages can be created when executing tasks or using the API of the platform "PSO.Bot.CriaMensagem" (PEX) or "Plataforma.Bot.CriaMensagem" (external integrations). The possibility to implement customizes Assistant messages ranges from product tutorials to users (since these messages can be created by PEX and display anywhere in the ERP) until the table and/or graphic display with relevant information, from asynchronous tasks. The integrator has total freedom to adapt and improve the perception of the product intelligence, surprising the user with suggestions on the following tasks of its workflow or enlightening information to support decision-making, by crossing data from several ERP tables, external data or even the own PRIMAVERA Cloud infrastructure. To create messages during the execution of an asynchronous task, use the following code: The message display language depends on the language used on the ERP. To implement messages considering the language, follow these steps: The resulting text will be a json string with the structured message. If necessary, you can specify in the parameters the literals that must fill in the identifiers "{0}, {1}, {...}" to compose the string. To exemplify, let's consider one of the tasks currently available in Echo - the client update from the information in the PRIMAVERA services. The message present in the text resource must follow one of these models: "The details for customer {0} have changed. Do you want to update the customer file data? {1} | {2}. Learn more {3}.", making it clear where the actions will be created. The options "CancelIfAnyRelatedActionHasExecuted" and "RelatedActionsIndexes" are meant to cancel the action if another related action is executed, which means that the user or other users pressed "Yes for all", the action will not produce any result, considering that the related action is more comprehensive than the current one. All actions must be added to the message previously created, this way: Next, we show you how to create the results lists and the three different ways of presenting the results: text, tables and charts. 1. Fill in the results: In this example, we use the client value (ALCAD) to create a drilldown link for the client file. 2. Display the results. The view to display is selected using the object "ViewConfig" from the object "BotMessageResults" created in the previous step. It is also possible to create Bot messages when using the ERP from the APIs mentioned in the start of the article. By the current limitation of the integration with the ERP, these messages cannot have results, but as an alternative, it is possible to insert actions in the messages, as explained. Note: Moving actions with the engine can be performed using the object "PrimaveraOrderedDictionary", in the "objAccoes" parameter of the function "Plataforma.Bot.CriaMensagem". This object can contain one or more actions of the type "Primavera.Bot.Engine100.ErpViewModel.BotActionDto". If there are no actions, it is possible to move a blank in this parameter. Thus, it is possible, for example, to schedule tasks in ECHO, in which the assistant requests a confirmation before scheduling the task execution. The detailed code in this article is available in the PRIMAVERA GitHub page.Create messages
BotMessage companyMessage = this.InitializeNewMessage(instance, user.Code, messageText);
companyMessage.CompanyId = enterprise.Code;
string messageText = Entities.Helpers.Functions.GetAllAvailableCulturesForResource(Properties.Resources.ResourceManager, "RES_Text", param1, param2, ...);
Implement an action in the message
new BotMessageAction()
{
ActionIndex = 0,
ActionType = BotMessageActionType.Drilldown,
ActionParameters = "GCP|1|GCP_MOSTRAMANUTENCAO|Manutencao=mnuTabClientes|Entidade=ALCAD",
Text = "ALCAD"
}, new BotMessageAction()
{
ActionIndex = 1,
ActionType = BotMessageActionType.ScheduleUserTask,
TaskParameters = new BotMessageActionTaskParameters()
{
CancelIfAnyRelatedActionHasExecuted = true,
RelatedActionsIndexes = new Collection() { "3" },
TopicId = this.TopicId,
TaskId = "ExecuteEntityUpdate",
PipelineId = SyncEntityPipelineName,
ExecutionParameters = "Company=DEMO|Customers=ALCAD"
},
Text = Entities.Helpers.Functions.GetAllAvailableCulturesForResource(Properties.Resources.ResourceManager, YesResource, null)
},new BotMessageAction()
{
ActionIndex = 3,
ActionType = BotMessageActionType.ResultsPage,
ActionParameters = string.Empty,
Text = Entities.Helpers.Functions.GetAllAvailableCulturesForResource(Properties.Resources.ResourceManager, HereResource, null)
},Collection() actions = new Collection();
actions.Add(new BotMessageAction() {.....});
actions.Add(new BotMessageAction() {.....});
actions.Add(new BotMessageAction() {.....});
companyMessage.Actions = actions;Create result lists
var results = new BotMessageResults();
results.AddDataTableToResultSet(dataTableComOsDados);
companyMessage.Results = results;
// or for ex.
DataTable dt = new DataTable();
dt.Columns.Add("Mês", typeof(string));
dt.Columns.Add("Vendas", typeof(int));
dt.Rows.Add("Janeiro", 32);
dt.Rows.Add("Fevereiro", 45);
dt.Rows.Add("Março", 54);
dt.Rows.Add("Abril", 110);
dt.Rows.Add("Maio", 150);
dt.Rows.Add("Junho", 120);
dt.Rows.Add("Julho", 80);
dt.Rows.Add("Agosto", 10);
dt.Rows.Add("Setembro", 5);
dt.Rows.Add("Outubro", 15);
dt.Rows.Add("Novembro", 25);
dt.Rows.Add("Dezembro", 70); foreach (List linha in results.ResultSets.First())
{
// Add action for the first column (entity, ex: "Sofrio")
linha[1].Action = new BotMessageAction()
{
ActionIndex = 0,
ActionType = BotMessageActionType.Drilldown,
ActionParameters = string.Concat("GCP|1|GCP_MOSTRAMANUTENCAO|Manutencao=mnuTabClientes|Entidade=" + linha[0].Value),
Text = linha[1].Value
};
}var results = new BotMessageResults();
Collection valuesList = new Collection();
valuesList.Add(new Cell()
{
Action = null,
Name = "Janeiro",
Value = "32"
});
valuesList.Add(new Cell()
{
Action = null,
Name = "Fevereiro",
Value = "45"
});
results.AddValuesListToResultSet(valuesList);
companyMessage.Results = results; results.ViewConfig.Add(
new Entities.Results.TableView()
{
Order = 0,
Columns = new System.Collections.ObjectModel.Collection()
{
new Entities.Results.Column()
{
Name = string.Empty,
Visible = false
},
new Entities.Results.Column()
{
Name = Entities.Helpers.Functions.GetAllAvailableCulturesForResource(Properties.Resources.ResourceManager, NameResource, null),
Visible = true
},
},
ResultSet = 0,
ShowTitle = true,
Title = Entities.Helpers.Functions.GetAllAvailableCulturesForResource(Properties.Resources.ResourceManager, OutdatedDataResource, null)
}); results.ViewConfig.Add(new Entities.Results.GraphView()
{
Columns = new Collection()
{
new Column() { Name = "Mês", Visible = true, Axis = "x" },
new Column() { Name = "Vendas", Visible = true }
},
Order = 0,
GraphType = GraphType.Bar,
ResultSet = 0,
ShowTitle = true,
Title = "Vendas"
});results.ViewConfig.Add(
new Entities.Results.LabelView()
{
Order = 0,
Text = "Text to present on the label"
});