bot4s / telegram

Telegram Bot API Wrapper for Scala
Apache License 2.0
418 stars 101 forks source link

InlineQueryResultArticle doesn't send type? #64

Closed Follpvosten closed 6 years ago

Follpvosten commented 6 years ago

Hello, I'm having a problem with answering inline queries. Library version is 4.0.0-RC1. System information:

 ~/testproject $ uname -a
 FreeBSD scaladev 11.1-RELEASE-p10 FreeBSD 11.1-RELEASE-p10 #0: Tue May  8 05:21:56 UTC 2018     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64
 ~/testproject $ scala -version
 Scala code runner version 2.12.6 -- Copyright 2002-2018, LAMP/EPFL and Lightbend, Inc.
 ~/testproject $ java -version
 openjdk version "1.8.0_172"
 OpenJDK Runtime Environment (build 1.8.0_172-b11)
 OpenJDK 64-Bit Server VM (build 25.172-b11, mixed mode)

sbt version is 1.0.

This is the whole code (things are named like that because I'm just starting to try out things):

 import com.bot4s.telegram.api.declarative.InlineQueries
 import com.softwaremill.sttp.okhttp.OkHttpFutureBackend
 import com.bot4s.telegram.clients.SttpClient
 import com.bot4s.telegram.methods._
 import com.bot4s.telegram.models._
 import slogging.{LogLevel, LoggerConfig, PrintLoggerFactory}

 class EchoBot(val token: String) extends TelegramBot with Polling with InlineQueries {
   LoggerConfig.factory = PrintLoggerFactory()
   LoggerConfig.level = LogLevel.TRACE

   onInlineQuery { implicit q =>
     val results = Seq(
       InlineQueryResultArticle("1", "Klingt lustig",
         inputMessageContent = InputTextMessageContent("Klingt lustig")))
     answerInlineQuery(results, Some(60))                                                                                                                                                   
   }                                                                                                                                                                              

   implicit val backend = OkHttpFutureBackend()                                                                                                                                             
   override val client: RequestHandler = new SttpClient(token)                                                                                                                              
 }

 object Hello extends App {
   new EchoBot("<bot token>").run()
 }

When the bot receives an inline query, the output looks like this:

 [trace, com.bot4s.telegram.clients.SttpClient] REQUEST c529aba4-79d6-4cca-87eb-cb8c9d9f8a77 AnswerInlineQuery(1302304079610336554,List(InlineQueryResultArticle(1,Klingt lustig,InputTextMessageContent(Klingt lustig,None,None),None,None,None,None,None,None,None,article)),Some(60),None,None,None,None)
 [error, com.bot4s.telegram.clients.SttpClient] RESPONSE c529aba4-79d6-4cca-87eb-cb8c9d9f8a77 java.util.NoSuchElementException: Status code 400: {"ok":false,"error_code":400,"description":"Bad Request: can't find field \"type\""}

I don't actually know if this is a problem with the library, but I think it might be. If it's a user error, then I'm sorry and would like to know how to do it properly. Thanks!

mukel commented 6 years ago

Thanks for the excellent bug report! Indeed circe encoding for sealed traits hierarchies breaks the expected JSON structure, note that this is a just a residual bug due to the migration from json4s to circe. A fix already landed in 491d5cdfe90bb9603154f8a8f5040944a347d5d8 please do report any further bugs.