teloxide/cg

Reserved keywords are not renamed

luminosoda opened this issue · 1 comments

The sendPoll method has a type parameter, and since this is reserved keyword, code generator patches it to type_, but doesn't add a serde macro to rename it back to type when serialization occurs. Thus, this method always creates a regular poll, and Telegram simply ignores this type_ extra field.
I have not found any mention of this, it seems that this mistake exists from the very beginning.

Example code
use teloxide::prelude::*;
use serde::Serialize;
use serde_json::value::Serializer;

#[tokio::main]
async fn main() {
  run().await;
}

async fn run() {
  let token = "TOKEN";
  let chat_id = 1;
  let bot = Bot::new(token);

  let options = vec![
      "Waffle".to_string(),
      "Coffee".to_string(),
      "Tea".to_string(),
      "Omelette".to_string(),
      "Fried tentacles".to_string(),
  ];
  let request = bot
      .send_poll(
          chat_id,
          "What is the best way to start the morning?",
          options,
          teloxide::types::PollType::Quiz,
      )
      .correct_option_id(0);

  let output = request.serialize(Serializer).unwrap();
  let type_ = output.get("type_").unwrap();
  println!("{}", type_);
}

For the future: please, open issues at https://github.com/teloxide/teloxide/issues, there they are a lot easier to track and notice 😅