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

Constructing a new poll #66

Closed
TwistingTwists opened this issue Sep 22, 2021 · 6 comments
Closed

Constructing a new poll #66

TwistingTwists opened this issue Sep 22, 2021 · 6 comments

Comments

@TwistingTwists
Copy link

What methods are available for making new poll ?

I can see

    model(Poll, [
      {:id, :string},
      {:question, :string},
      {:options, {:array, PollOption}},
      {:total_voter_count, :integer},
      {:is_closed, :boolean},
      {:is_anonymous, :boolean},
      {:type, :string},
      {:allows_multiple_answers, :boolean},
      {:correct_option_id, :integer, :optional},
      {:explanation, :string, :optional},
      {:explanation_entities, {:array, MessageEntity}, :optional},
      {:open_period, :integer, :optional},
      {:close_date, :integer, :optional}
    ])

implemented. What's the corresponding function?

@rockneurotiko
Copy link
Owner

rockneurotiko commented Sep 22, 2021

👋🏼

To create a poll you have to use the sendPoll method:

method(
    :post,
    "sendPoll",
    [
      {chat_id, [:integer, :string]},
      {question, [:string]},
      {options, [{:array, :string}]},
      {is_anonymous, [:boolean], :optional},
      {type, [:string], :optional},
      {allows_multiple_answers, [:boolean], :optional},
      {correct_option_id, [:integer], :optional},
      {explanation, [:string], :optional},
      {explanation_parse_mode, [:string], :optional},
      {explanation_entities, [{:array, MessageEntity}], :optional},
      {open_period, [:integer], :optional},
      {close_date, [:integer], :optional},
      {is_closed, [:boolean], :optional},
      {disable_notification, [:boolean], :optional},
      {reply_to_message_id, [:integer], :optional},
      {allow_sending_without_reply, [:boolean], :optional},
      {reply_markup, [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],
       :optional}
    ],
    ExGram.Model.Message
  )

Something like:

ExGram.send_poll(chat_id, "Question?", ["Option1", "Option2"])

You can find the method's help in the iex repl:

iex(8)> h ExGram.send_poll

            def send_poll(chat_id, question, options, options \\ [])            

  @spec send_poll(
          chat_id :: integer() | String.t(),
          question :: String.t(),
          options :: [String.t()],
          options :: [
            is_anonymous: boolean(),
            type: String.t(),
            allows_multiple_answers: boolean(),
            correct_option_id: integer(),
            explanation: String.t(),
            explanation_parse_mode: String.t(),
            explanation_entities: [ExGram.Model.MessageEntity.t()],
            open_period: integer(),
            close_date: integer(),
            is_closed: boolean(),
            disable_notification: boolean(),
            reply_to_message_id: integer(),
            allow_sending_without_reply: boolean(),
            reply_markup:
              ExGram.Model.InlineKeyboardMarkup.t()
              | ExGram.Model.ReplyKeyboardMarkup.t()
              | ExGram.Model.ReplyKeyboardRemove.t()
              | ExGram.Model.ForceReply.t(),
            adapter: atom(),
            bot: atom(),
            token: String.t(),
            debug: boolean(),
            check_params: boolean()
          ]
        ) :: {:ok, ExGram.Model.Message.t()} | {:error, ExGram.Error.t()}

Check the documentation of this method in
https://core.telegram.org/bots/api#sendpoll

@TwistingTwists
Copy link
Author

TwistingTwists commented Sep 22, 2021

Thanks!

One more question :
I see h ExGram.send_poll in iex -S mix
but cannot find its implementation method(:post, ..... in the directory. (used Ctrl+F)

These are all functions I see.
image

Am I missing something?

@rockneurotiko
Copy link
Owner

rockneurotiko commented Sep 22, 2021

You can ask all the questions you want, no problem.

In order to avoid repetition, this library uses scraping + macros to create the basic models and functionality.

In fact, this line creates the method send_poll with the parameters needed: https://github.com/rockneurotiko/ex_gram/blob/master/lib/ex_gram.ex#L401

EDIT: Currently there are 77 methods, maybe you are not finding it because of the formatter the line has a line break

@TwistingTwists
Copy link
Author

Line Break it was!

I just skimmed through the .py file you use to scrape - Appreciate this approach to avoid repetition !

Thank you so much!

@rockneurotiko
Copy link
Owner

I usually specify them as a keyword list, I think you can use a map too, but as a keyword list is cleaner:

ExGram.send_poll(chat_id, "Question?", ["Option1", "Option2"], type: "quiz", correct_option_id: 0) # You need to set a correct option for quizes

@TwistingTwists
Copy link
Author

This helps! Thanks.

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