Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline mode support #42

Closed
p4vook opened this issue Mar 4, 2021 · 17 comments
Closed

Inline mode support #42

p4vook opened this issue Mar 4, 2021 · 17 comments

Comments

@p4vook
Copy link
Contributor

p4vook commented Mar 4, 2021

Can I program an inline mode bot using this library?

@swamp-agr
Copy link
Collaborator

There is no support for inline mode right now.

@gDanix
Copy link
Contributor

gDanix commented Mar 15, 2021

Will this be difficult to implement?

I'm still learning Haskell, but I feel like this could be easily implemented, just by defining an InlineQuery record, let Aeson parse it, and build an Update from there. But I guess I would need some help from the current collaborators...

@p4vook
Copy link
Contributor Author

p4vook commented Mar 15, 2021

Well, I tried doing exactly this, but I stuck with something that looks like an infinite recursion during parsing the query and I have no idea, how to fix or debug this.

@swamp-agr
Copy link
Collaborator

@pavel-the-best May I kindly ask you to share the code you are currently working with in order to help you with infinite recursion?

@p4vook
Copy link
Contributor Author

p4vook commented Mar 16, 2021

@gDanix
Copy link
Contributor

gDanix commented Apr 17, 2021

Hi!

Sorry for the long delay.

I've been able to test @pavel-the-best implementation and it looks really good. I've been able to receive correctly inline queries, but couldn't send back results for that query. Currently, the data type InlineQueryResult (https://github.com/pavel-the-best/telegram-bot-simple/blob/a3a88369ffeb7c73802f6fb6725653bdc752de0c/src/Telegram/Bot/API/InlineMode.hs#L68) has only the type, id, and contact fields, so the other ones, required for other types of results are missing. Tomorrow I will check if just adding some fields will do the work, let's see what I can do, because I've never messed with something as advanced as Aeson...

In any case, this looks cool!

@gDanix
Copy link
Contributor

gDanix commented Apr 18, 2021

Ok, I've been taking a closer look at this, and there is work to do to get the answers/results work (If I understood it correctly, when an inline query comes, the bot should send "answers", and when the user chooses one, that comes to the bot as a "result". Thus, "answer" and "result" are not the same). those dataclasses need to be made, and then hopefully it work. Although I'm very novice, I think I can do, at least, most of it, so I will post here any progress I make!

@p4vook
Copy link
Contributor Author

p4vook commented Apr 18, 2021

Can you please provide EchoBot example that you used for testing this?

@gDanix
Copy link
Contributor

gDanix commented Apr 19, 2021

Sorry, I didn't used EchoBot. I made a bot the last month (https://git.sr.ht/~gdanix/marlin_gcode_info_bot), and I wanted to add inline mode to it, so I've been messing with my bot. In any case, I didn't do anything special, just created the bot with traceBotDefault, and then saw that the inline mode queries started to get parsed and showed in the terminal.

I remember I had to uncomment 2 lines from Bot/API.hs to make it work, but it's just a matter of imports/exports.

@gDanix
Copy link
Contributor

gDanix commented Apr 21, 2021

Good news!!

I've been able to complete a minimal working support for inline mode, and modified EchoBot to make use of it. Now, it should respond to inline queries echoing the query itself.

I'm going to work now on cleaning up, documenting and structuring a bit better the dataclasses I've created.

One downside is that conversationBot doesn't work with inline mode, probably because inline queries doesn't have a chat id.

I've uploaded all the code to my fork: https://git.sr.ht/~gdanix/telegram-bot-simple

This is my very first contribution to a Haskell project any feedback (doesn't need to be kind, don't worry) is appreciated!

P.S. I forgot to blur the name of my testing bot in the first screenshot... Doesn't matter...

imagen
imagen

@gDanix
Copy link
Contributor

gDanix commented Apr 24, 2021

Hi! I've done a bit more of work for inline mode.

I've implemented the InputMessageContent dataclasses (https://core.telegram.org/bots/api#inputmessagecontent) in their own module.
Also, I've moved the InlineQueryResultType to it's own module, with the goal of moving all the InlineQueryResult-related dataclasses there (https://core.telegram.org/bots/api#inlinequeryresult)
EchoBot has been updated to make use of the new dataclasses.

I've uploaded all the progress to my fork (https://git.sr.ht/~gdanix/telegram-bot-simple). Please @swamp-agr, let me know if you can grab the changes from there and publish here, or if you prefer me to open a Pull Request.

Currently, with these latest additions, a bot can respond to inline queries, and can send back only article results (text, basically). Since all the InputMessageContent dataclasses are in place, these article displayed to the user can result in a text message (like in the above screenshots), but also in a venue, location or contact message.

What's left to do is to implement the different result dataclasses. There are a huge number of them, but also the article result must be completed (url, reply_markup, and so on). Also the ChosenInlineResult.

@gDanix
Copy link
Contributor

gDanix commented May 8, 2021

Hi!

I've been looking for a "contributing" file, and I didn't find it. I would really like this library to be complete. Sadly, this is my first time contributing to a Haskell library, and I'm a bit lost. I'm sorry if I didn't do things right.

What would be an appropriate plan for delivering this inline mode? To build it on top of the latest version? (I just continued working from the @pavel-the-best work). I guess, since the project is in GitHub, the PR workflow must be followed.

@swamp-agr
Copy link
Collaborator

Hi @gDanix,

Please go ahead and open pull request. You contribution is welcome here.
I will let you know if something should be changed among the way during review process.

Best Regards,
@swamp-agr

@gDanix
Copy link
Contributor

gDanix commented May 10, 2021

Thank you so much!!

I will redo my changes on top of the latest version (0.3.5, IIRC) and open a PR.

I don't think it would be necessary to backport them to previous versions. but let me know if you're interested!

@swamp-agr
Copy link
Collaborator

🎉 Inline support from #45 released on hackage: telegram-bot-simple-0.3.7.
👍 @gDanix @pavel-the-best thank you!

@swamp-agr
Copy link
Collaborator

If there's nothing to add feel free to close the issue.

@swamp-agr
Copy link
Collaborator

Closing in absence of comments. Feel free to re-open at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants