Prepr now offers a new Polls feature in the On Air timeline. Creating a poll is as simple as inputting the central question and the answer options. Add some artwork and media if needed and publish with just one click. The poll can automatically be published in your app and on your website via our API. More about the basics of the poll can be found in our blog. https://getprepr.com/blog/increase-listener-engagement-with-cross-channel-polls
In this example we will give you an idea on how to use the Poll in your apps.
The most common way to start showing the poll in the app is to use a Webhook to look for new published polls. To learn more about the Webhooks check the Webhooks tutorial page. For the poll you should subscribe the webhook to the publication.published
and publication.unpublished
events.
It is also possible to regularly poll the /publications endpoint for new published polls.
Once you receive a new Poll on the webhook, you can fetch the details of the poll by requesting the /publications/{id} endpoint with the fields poll_answers
and assets
.
Here is an example response with the fields build like this: poll_answers,assets{source_file{resized{banner.width(232).h(232)}}}
should contain everything you need to display the poll.
{
"id": "e7a708d1-3855-4dc0-9499-8f1b3c21e7bd",
"created_on": "2018-05-15T13:24:21+00:00",
"changed_on": "2018-06-12T09:46:28+00:00",
"published_on": "2018-05-15T13:23:00+00:00",
"unpublish_on": null,
"label": "Poll",
"status": "published",
"slug": null,
"body": "Will Trump negotiate a deal with Kim?",
"url": "https://edition.cnn.com/politics/live-news/trump-kim-jong-un-meeting-summit/index.html",
"assets": [
{
"id": "7496d0ae-4fdf-4943-acf2-5467b017a90d",
"created_on": "2018-06-12T09:45:58+00:00",
"changed_on": "2018-06-12T09:46:07+00:00",
"label": "Photo",
"name": null,
"body": null,
"reference": null,
"author": null,
"source_file": {
"id": "3bf2b2f5-dc90-4a74-9685-4a6e3e639879",
"created_on": "2018-06-12T09:45:58+00:00",
"changed_on": null,
"label": "SourceFile",
"original_name": "dd0a2add-6b68-4922-a63b-b975341e0f7e.jpg",
"mime_type": "image/jpeg",
"file_size": 79489,
"file": "https://s3.eu-central-1.amazonaws.com/s3-mediaconnect/3bf2b2f5-dc90-4a74-9685-4a6e3e639879",
"cdn_url": "https://d1oj8bnxrmcldu.cloudfront.net/{format}/s3-mediaconnect/3bf2b2f5-dc90-4a74-9685-4a6e3e639879.jpg",
"resized": {
"banner": "https://d1oj8bnxrmcldu.cloudfront.net/w_232,h_232/s3-mediaconnect/3bf2b2f5-dc90-4a74-9685-4a6e3e639879.jpg"
}
}
}
],
"poll_answers": [
{
"id": "1ddd48cc-137f-4b20-8ae7-cbfe30e5a0de",
"created_on": "2018-05-15T13:24:21+00:00",
"changed_on": "2018-06-12T09:46:28+00:00",
"published_on": "2018-06-12T09:46:28+00:00",
"unpublish_on": null,
"label": "PollAnswer",
"status": "published",
"slug": null,
"alternatives": [
""
],
"body": "No, they will be out of the room in minutes"
},
{
"id": "18351664-53dc-46c4-956a-fe179c2a7c5c",
"created_on": "2018-05-15T13:24:21+00:00",
"changed_on": "2018-06-12T09:46:28+00:00",
"published_on": "2018-06-12T09:46:28+00:00",
"unpublish_on": null,
"label": "PollAnswer",
"status": "published",
"slug": null,
"alternatives": [
""
],
"body": "Yes, he will get the best deal possible"
}
]
}
To vote on a an answer do a POST request to the publication /publications/{id}/vote endpoint. In our example case the vote url would look like this /publications/18351664-53dc-46c4-956a-fe179c2a7c5c/vote
.
If you want to record the persons voting history the endpoint supports a request with the session_hash
param.
Once you receive a poll unpublished event on the webhook, you can fetch the vote totals of the poll by requesting the /publications/{id} endpoint with the fields poll_answers{voted_count}
.
It its also possible to fetch the voted count when voting is still going on.
{
"id": "e7a708d1-3855-4dc0-9499-8f1b3c21e7bd",
"created_on": "2018-05-15T13:24:21+00:00",
"changed_on": "2018-06-12T09:46:28+00:00",
"published_on": "2018-05-15T13:23:00+00:00",
"unpublish_on": null,
"label": "Poll",
"status": "published",
"slug": null,
"body": "Will Trump negotiate a deal with Kim?",
"url": "https://edition.cnn.com/politics/live-news/trump-kim-jong-un-meeting-summit/index.html",
"poll_answers": [
{
"id": "18351664-53dc-46c4-956a-fe179c2a7c5c",
"created_on": "2018-05-15T13:24:21+00:00",
"changed_on": "2018-06-12T09:46:28+00:00",
"published_on": "2018-06-12T09:46:28+00:00",
"unpublish_on": null,
"label": "PollAnswer",
"status": "published",
"slug": null,
"alternatives": [
""
],
"body": "Yes, he will get the best deal possible",
"voted_count": 9842
},
{
"id": "1ddd48cc-137f-4b20-8ae7-cbfe30e5a0de",
"created_on": "2018-05-15T13:24:21+00:00",
"changed_on": "2018-06-12T09:46:28+00:00",
"published_on": "2018-06-12T09:46:28+00:00",
"unpublish_on": null,
"label": "PollAnswer",
"status": "published",
"slug": null,
"alternatives": [
""
],
"body": "No, they will be out of the room in minutes",
"voted_count": 731
}
]
}