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

writing send_poll Protocol - help needed. #72

Closed
TwistingTwists opened this issue Oct 11, 2021 · 4 comments
Closed

writing send_poll Protocol - help needed. #72

TwistingTwists opened this issue Oct 11, 2021 · 4 comments

Comments

@TwistingTwists
Copy link

TwistingTwists commented Oct 11, 2021

Hello,

Objective:

To make send_poll pipe-able I am trying to make following changes to library.

so I want to use it like
context |> answer('anyhting') |> send_poll(id,"question",['1','2'],type:"quiz",correct_option_id: 0)

what I did?

  1. add send_poll.ex protocol implementation responses folder
  2. adding SendPoll as import alias in dsl.ex
  3. adding send_poll function in dsl.ex

Where I need help?

  1. Do I need to touch any other file?
  2. in answer Here -- What does add_answer do?

I'll create a PR once I get a response from you and sort things out!

@rockneurotiko
Copy link
Owner

Hello!

That's all you need to do to add a new response, indeed.

The DSL functions in dsl.ex (answer, answer_callback, ...) do two things. First creates the response structure with the correct options, and then adds the answer to the answers list in the context (using add_answer)

For example, afwer the pipe of your issue, you would end with a context with two items in the answers list, one Answer and one SendPoll (Something like %Context{answers: [%Answer{...}, %SendPoll{}]})

When you return the context at the end of your handle methods, the library will try to send all the answers (But you can do it manually with send_answers/1 at any time if you prefer)

You can see here where it happens in the dispatcher. https://github.com/rockneurotiko/ex_gram/blob/master/lib/ex_gram/dispatcher.ex#L255

@TwistingTwists
Copy link
Author

Right!

I am trying to build middlewares for my specific needs. And %Context{answers: [%Answer{...}, %SendPoll{}]} is an aim.
I'll submit PR then in few hours!

Side Question

  1. Is is possible to implement Protocols in Responses folder for all methods via .py file?
    I'll be happy to chime in if you have a lead on that.

@rockneurotiko
Copy link
Owner

Feel free to submit any PR, I'll try to review it as soon as possible to give feedback and approve it when everything is right 😄

About generating the Responses, I don't think I would like that. I don't want all the methods to have a response, only the ones useful to have a balance between simple and useful client API. Also, some Responses really need custom code (check ExGram.Responses.EditInline), so it would be complicated to auto-generate the code.

@TwistingTwists
Copy link
Author

TwistingTwists commented Oct 11, 2021

https://github.com/rockneurotiko/ex_gram/blob/master/lib/ex_gram/dsl.ex#L24

What corner case does this method in answer cover? I felt that above two definitions were enough.

  1. Why check m as map?
  2. I see that it does include a case with NO options. (and hence passes empty list to function below.)

I might need to implement similar in send_poll function.

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

2 participants