title: Telegram Bot custom keyboard in C#
body: <p>I tried to create message with custom keyboard. So I send request with</p>
  
  <pre><code>reply_markup = {&quot;keyboard&quot;:[[&quot;1&quot;],[&quot;2&quot;]],&quot;resize_keyboard&quot;:&quot;True&quot;,&quot;one_time_keyboard&quot;:&quot;True&quot;}
  </code></pre>
  <p>But, it does not work.</p>
  <p>I tried all of Content-Types:</p>
  <ol>
  <li>application/x-www-form-urlencoded (create message with default
  keyboard)</li>
  <li>application/json (create message with default keyboard)</li>
  <li>multipart/form-data (does not work at all, inspite of <a href="https://www.reddit.com/r/Telegram/comments/3bblz0/sendmessage_with_replykeyboardmarkup_problem" rel="nofollow noreferrer">this Post</a>)</li>
  </ol>
  <p>I also tried to send message by 2 different ways. What's the wrong with this code?</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.IO;
  using System.Net;
  
  namespace DutyReminder
  {
  class Program
  {
      static void Main(string[] args)
      {
  
          string message = &quot;message&quot;;
          string message1 = &quot;message1&quot;;
          string botid = &quot;165749848:AAGtjn42bajF-WxdKosTF07sLwJPYlqiDZE&quot;;
          string chatid = &quot;38651047&quot;;
  
          Sender.send(&quot;&quot;, &quot;https://api.telegram.org/bot&quot; + botid + &quot;/sendmessage?chat_id=&quot; + chatid + &quot;&amp;text=&quot; + message + &quot;&amp;reply_markup={\&quot;keyboard\&quot;:[[\&quot;1\&quot;],[\&quot;2\&quot;]],\&quot;resize_keyboard\&quot;:\&quot;True\&quot;,\&quot;one_time_keyboard\&quot;:\&quot;True\&quot;}&quot;);
          Sender.HttpPost(&quot;https://api.telegram.org/bot&quot; + botid + &quot;/sendmessage?chat_id=&quot; + chatid + &quot;&amp;text=&quot; + message1 + &quot;&amp;reply_markup={\&quot;keyboard\&quot;:[[\&quot;1\&quot;],[\&quot;2\&quot;]],\&quot;resize_keyboard\&quot;:\&quot;True\&quot;,\&quot;one_time_keyboard\&quot;:\&quot;True\&quot;}&quot;, &quot;&quot;);
  
      }
  }
  
  static class Sender
  {
      static public void send(string message, string url)
      {
          // Create a request using a URL that can receive a post. 
          WebRequest request = WebRequest.Create(url);
          // Set the Method property of the request to POST.
          request.Method = &quot;POST&quot;;
          // Create POST data and convert it to a byte array.
          //string postData = &quot;{\&quot;value1\&quot;:\&quot;&quot; + message + &quot;\&quot;}&quot;;
          string postData = message;
          byte[] byteArray = Encoding.UTF8.GetBytes(postData);
          // Set the ContentType property of the WebRequest.
          request.ContentType = &quot;application/x-www-form-urlencoded&quot;;
          // Set the ContentLength property of the WebRequest.
          //  request.ContentLength = byteArray.Length;
          // Get the request stream.
          Stream dataStream = request.GetRequestStream();
          // Write the data to the request stream.
          dataStream.Write(byteArray, 0, byteArray.Length);
          // Close the Stream object.
          dataStream.Close();
          // Get the response.
          WebResponse response = request.GetResponse();
          // Display the status.
          Console.WriteLine(((HttpWebResponse)response).StatusDescription);
          // Get the stream containing content returned by the server.
          dataStream = response.GetResponseStream();
          // Open the stream using a StreamReader for easy access.
          StreamReader reader = new StreamReader(dataStream);
          // Read the content.
          string responseFromServer = reader.ReadToEnd();
          // Display the content.
          Console.WriteLine(responseFromServer);
          // Clean up the streams.
          reader.Close();
          dataStream.Close();
          response.Close();
      }
  
  
      static public string HttpPost(string URI, string Parameters)
      {
          System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
        //  req.Proxy = new System.Net.WebProxy(ProxyString, true);
          //Add these, as we're doing a POST
          req.ContentType = &quot;application/x-www-form-urlencoded&quot;;
          req.Method = &quot;POST&quot;;
          //We need to count how many bytes we're sending. Post'ed Faked Forms should be name=value&amp;
          byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
          req.ContentLength = bytes.Length;
          System.IO.Stream os = req.GetRequestStream();
          os.Write(bytes, 0, bytes.Length); //Push it out there
          os.Close();
          System.Net.WebResponse resp = req.GetResponse();
          if (resp == null) return null;
          System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
          return sr.ReadToEnd().Trim();
      }
  
  }
  }
  </code></pre>