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

Expose/access the Poll-ID when creating via API #418

Open
netgrain opened this issue Apr 13, 2022 · 2 comments
Open

Expose/access the Poll-ID when creating via API #418

netgrain opened this issue Apr 13, 2022 · 2 comments
Labels
Help Wanted Community help wanted Needs Spec Needs further specification to be a good (help wanted) ticket Tech/Server Plugin Server Type/Enhancement New feature or request
Milestone

Comments

@netgrain
Copy link

Summary

AFAIK the unique Poll-ID is not exposed when creating polls, nor can be accessed via an API-endpoint after the poll has been created. This would be necessary in order to interact with the poll after creation, such as for ending a poll/adding options etc. Particularly useful for various integrations initiated by a bot-account.

So is it possible to return the Poll-ID when creating a poll or have I missed something?

Example API

Start poll - request

curl -i -s -X POST -H 'Content-Type: application/json' -H 'Authorization: Bearer <account_identifier>' -d '{ "channel_id":"<channel_identifier>", "command":"/poll "Is Matterpoll great?" "1" "2" "3" --votes=1"}' "https://<MM-server>/api/v4/commands/execute"

Start poll - response

{"response_type":"","text":"","username":"","channel_id":"","icon_url":"","type":"","props":null,"goto_location":"","trigger_id":"<trigger_id>","skip_slack_parsing":false,"attachments":null,"extra_responses":null}

End poll - request

curl -i -s -X POST -H 'Content-Type: application/json' -H 'Authorization: Bearer <account_identifier>' "https://<MM-server>/api/v4/posts/<poll-id>/actions/endPoll"

Suggestion

return rPost.Id as part of https://github.com/matterpoll/matterpoll/blob/master/server/plugin/command.go#L92

@kaakaa kaakaa added the Question Further information is requested label Apr 30, 2022
@kaakaa kaakaa added this to the Backlog milestone Apr 30, 2022
@kaakaa
Copy link
Contributor

kaakaa commented Apr 30, 2022

Particularly useful for various integrations initiated by a bot-account.

It sounds interesting.

At first, in Materpoll, PollID and PostID are words that refer to different things, and what you want seems to be PostID. PostID is a term in Mattermost, and PollID is a Matterpoll-specific term that is handled internally to manage a poll. For now, Matterpoll is not intended to be executed directly from the API, so it doesn't return PostID (and PollID) when creating a poll.

Unfortunately even if we were to change Matterpoll to return PostId, it wouldn't be able to call the actions such as ending/deleting a poll directly through http request as you wrote, because the actions needs confirmation from interactive dialog. So it's needed to implement new endpoints for manipulating a poll directly by http request. But it would be quite a hassle. Because AFAIK Mattermost plugin system doesn't support an authorization layer for plugin API (Matterpoll currently implements an authorization layer only assuming it is executed from Mattermost UI) and that layer must be implemented by plugin developer. It need a much efforts, and I don't have enough time for it.

As a different approach, it may be a hacky, but it may be possible to achieve by adding an implementation that returns PollID when creating and then implementing a plugin that uses PluginHTTP to call API endpoints of Matterpoll.

@hanzei
Copy link
Member

hanzei commented Sep 19, 2022

RE adding a seperate API: That seems like the clean solution to me. The authentication should not be an issue. We can re use most of the existing code and rely on the Mattermost session. Still, it's a lot of work.

@hanzei hanzei added Needs Spec Needs further specification to be a good (help wanted) ticket Help Wanted Community help wanted Tech/Server Plugin Server Type/Enhancement New feature or request and removed Question Further information is requested labels Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted Community help wanted Needs Spec Needs further specification to be a good (help wanted) ticket Tech/Server Plugin Server Type/Enhancement New feature or request
Development

No branches or pull requests

3 participants