public static IList <Block> BuildOrderMessage(Order order) { var blocks = new List <Block>(); /* Summary */ var costSummary = new SectionBlock() { BlockId = "order_costs", }; var payload = order.IsOpen ? new Markdown($":hourglass_flowing_sand: Order in progress by {order.Owner.FriendlyName}:\n") : new Markdown($":checkered_flag: Order complete by {order.Owner.FriendlyName}:\n"); if (order.Costs != null) { foreach (var cost in order.Costs.Values.Where(x => x.Value > 0)) { payload.Text += $"{cost.MarkdownDescription}\n"; } } if (order.SharedCost > 0) { payload.Text += $"> • shared: *{order.SharedCost}*\n"; } payload.Text += $"> ---\n> Total: *{order.GetTotalCost()}*"; costSummary.Text = payload; blocks.Add(costSummary); blocks.Add(new DividerBlock()); var context = new ContextBlock { BlockId = "order_context", Elements = new List <IContextElement>() }; if (order.IsOpen) { context.Elements.Add(new Markdown($"Available `/food ` commands: " + $"`{CommandTexts.Eat} <value> [food]`, " + $"`{CommandTexts.Shared} <value>`, " + $"`{CommandTexts.Finish}`, " + $"`{CommandTexts.Cancel}`" + $".")); if (!order.IsReadyForCompletion) { context.Elements.Add(new PlainText("\nOrder needs 2+ participants to be completed.")); } } else // order is closed { context.Elements.Add(new PlainText("This order may be reopened only until the next order is started.")); } blocks.Add(context); return(blocks); }
public Message Build(Notification notification) { var message = BlocksMessage.Create( ContextBlock.Create( PlainTextContextElement.Create(notification.Header) ), SectionBlock.Create( Markdown.Create($"*{notification.Title}*\n{notification.Content}") ), ActionsBlock.Create( Button.Create("Open in browser", notification.Url) ) ); message.ChannelId = _userDictionaryManager.Find(notification, _target); return(message); }
private ContextBlock DeserializeContextBlock(JToken json) { var block = new ContextBlock(); if (json["block_id"] != null) { block.BlockId = json["block_id"].Value <string>(); } var elements = json["elements"].AsJEnumerable(); var outputElements = new List <IContextElement>(); foreach (var element in elements) { var outputElement = this.DeserializeContextElement(element); outputElements.Add(outputElement); } block.Elements = outputElements; return(block); }