- adding SendTextFile to simplify sending csv or textfiles by code without saving them to harddrive
This commit is contained in:
parent
64311d0cd9
commit
7a7014cec3
@ -501,6 +501,34 @@ namespace TelegramBotBase.Sessions
|
||||
return m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a Textfile from scratch with the specified encoding. (Default is UTF8)
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <param name="textcontent"></param>
|
||||
/// <param name="encoding">Default is UTF8</param>
|
||||
/// <param name="caption"></param>
|
||||
/// <param name="buttons"></param>
|
||||
/// <param name="replyTo"></param>
|
||||
/// <param name="disableNotification"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Message> SendTextFile(String filename, String textcontent, Encoding encoding = null, String caption = "", ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false)
|
||||
{
|
||||
encoding = encoding ?? Encoding.UTF8;
|
||||
|
||||
var ms = new MemoryStream();
|
||||
var sw = new StreamWriter(ms, encoding);
|
||||
|
||||
sw.Write(textcontent);
|
||||
sw.Flush();
|
||||
|
||||
var content = ms.ToArray();
|
||||
|
||||
var m = await SendDocument(filename, content, caption, buttons, replyTo, disableNotification);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an document
|
||||
/// </summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user