Edit
Edit

Reputation: 393

how to use StringBuilder on telegram bot with c#?

I have create one API for the sending image with caption using ASP.NET C# on telegram bot. And I want to send link in the caption with create <a /> tag. But I have tried using StringBuilder to print the whole line same on telegram bot. I don't know how can do that. Any one know where is my problem in the code?

Here this is my API:

[System.Web.Http.AcceptVerbs("POST")]
public void SendCasesOnTelegramBot()
{            
    try
    {
        DataSet ds = DataAccess.ExecuteDataset(Setting.ConnectionString(), "GetPostForTelegramBot");
        if (ds != null && ds.Tables.Count > 0)
        {
            if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            {
                var Image = ds.Tables[0].Rows[0]["Url"].ToString();
                byte[] imageData = null;
                WebClient webClient = new WebClient();
                imageData = webClient.DownloadData(Image);
                MemoryStream ms = new MemoryStream(imageData);
                var sb = new StringBuilder();
                sb.Append("<a href='https://t.me/abc'>abc</a>"); // this is my tag.i want to juts print abc in the caption and i am click on abc work like link.                       
                sb.Append(Environment.NewLine);
                sb.Append(".");
                sb.Append(Environment.NewLine);
                sb.Append(".");
                sb.Append(Environment.NewLine);                   
                Bot.SendPhotoAsync("@abc", new FileToSend(ds.Tables[0].Rows[0]["Url"].ToString(), ms), sb.ToString());                      
            }
        }
    }
    catch (Exception ex)
    {                
    }
}

Here this is my image on telegram bot I have sent:

enter image description here

see in the image I have print same line but I don't want it like this. I want just print "abc" and click on abc work like link. Please help me and give some idea.

Upvotes: 0

Views: 679

Answers (1)

Daniel Park
Daniel Park

Reputation: 4021

Seems as if the bot API does not understand HTML tags when calling sendPhoto. If you want to use markup, you might have to send a subsequent message with the parseMode set to "HTML"

Upvotes: 1

Related Questions