/// <summary> /// Adding a HorizontalListBlock for chatbot /// </summary> /// <param name="elements"></param> /// <returns></returns> public ChatBotClient AddHorizontalListBlock(List <ChatBotElement> elements, string image_aspect_ratio) { MessageBlocks.Add(new Dictionary <string, object> { { "cards", new { elements, image_aspect_ratio } } }); return(this); }
/// <summary> /// Adding a ImageBlock for chatbot. /// </summary> /// <param name="imgUrl"></param> /// <returns></returns> public ChatBotClient AddImageBlock(string imgUrl) { MessageBlocks.Add(new Dictionary <string, object> { { "image", imgUrl } }); return(this); }
/// <summary> /// Adding a TextBlock for chatbot. /// </summary> /// <param name="text"></param> /// <returns></returns> public ChatBotClient AddTextBlock(string text) { MessageBlocks.Add(new Dictionary <string, object> { { "text", text } }); return(this); }
/// <summary> /// /// </summary> public void Clear() { MessageBlocks.Clear(); UpdateInnerText(); }
/// <summary> /// /// </summary> /// <param name="start"></param> /// <param name="length"></param> /// <param name="text"></param> public void Substitute(int start, int length, string text) { if (MessageBlocks.Count == 0 || start < 0 || length < 0) { return; } int count = 0; int startBlock = -1; int endBlock = -1; var blocks = new List <TextMessageBlock>(); for (int i = 0; i < MessageBlocks.Count; ++i) { if (start < count + MessageBlocks[i].Text.Length) { startBlock = i; break; } count += MessageBlocks[i].Text.Length; } if (startBlock == -1) { return; } var indexInStartBlock = start - count; for (int i = startBlock; i < MessageBlocks.Count; ++i) { if (start + length <= count + MessageBlocks[i].Text.Length) { endBlock = i; break; } count += MessageBlocks[i].Text.Length; } if (endBlock == -1) { return; } var indexInEndBlock = start + length - count; if (indexInStartBlock > 0) { blocks.Add(new TextMessageBlock(MessageBlocks[startBlock].Text.Substring(0, indexInStartBlock), MessageBlocks[startBlock].Foreground, MessageBlocks[startBlock].Background)); } blocks.Add(new TextMessageBlock(text, MessageBlocks[startBlock].Foreground, MessageBlocks[startBlock].Background)); if (indexInEndBlock < MessageBlocks[endBlock].Text.Length) { blocks.Add(new TextMessageBlock(MessageBlocks[endBlock].Text.Substring(indexInEndBlock), MessageBlocks[endBlock].Foreground, MessageBlocks[endBlock].Background)); } MessageBlocks.RemoveRange(startBlock, endBlock + 1 - startBlock); MessageBlocks.InsertRange(startBlock, blocks); UpdateInnerText(); }
/// <summary> /// /// </summary> /// <param name="text"></param> /// <param name="foreground"></param> /// <param name="background"></param> public void AppendText(string text, TextColor foreground, TextColor background) { MessageBlocks.Add(new TextMessageBlock(text, foreground, background)); UpdateInnerText(); }
/// <summary> /// /// </summary> /// <param name="text"></param> public void AppendText(string text) { MessageBlocks.Add(new TextMessageBlock(text)); UpdateInnerText(); }