nips/41.md

80 lines
1.9 KiB
Markdown
Raw Normal View History

2023-02-28 03:35:24 -05:00
# NIP-41 - Poll & Vote Event
2023-01-05 14:17:12 -05:00
`draft` `optional` `author:0xtlt`
2023-02-28 03:35:24 -05:00
> Poll and vote events are a way to create a poll and vote for it.\
> Polls are directly integrated into message events (1), and responses are vote events (9) to avoid overloading the loading of messages in clients.
## Specs
### Kind `1` - Message & Poll
To create a poll, include a `poll` tag in the message event. with the following format:
2023-02-28 03:44:16 -05:00
```text
2023-02-28 03:35:24 -05:00
tag: poll
options:
- <multi|single> allow others to reply with one or multiple options
- <ttl> TTL (in seconds|timestamp) when surv expires, 0 TTL don't expire
2023-02-28 03:41:01 -05:00
- <title> optional poll name ("" if not present)
2023-02-28 03:35:24 -05:00
- [<option>]: array of string
```
#### Example - Message
2023-01-05 14:17:12 -05:00
```json
{
...
"kind": 1,
"tags": [
...
2023-02-28 03:41:01 -05:00
["poll", "single", "0", "I'm a title!", "Option 1", "Option 2", "Option 3"],
2023-01-05 14:17:12 -05:00
...
],
}
```
2023-02-28 03:35:24 -05:00
### Kind `9` - Vote
2023-01-05 14:17:12 -05:00
2023-02-28 03:35:24 -05:00
To vote for a poll, you have to send an event kind `9`.\
The format of the event is the following:
2023-01-05 14:17:12 -05:00
2023-02-28 03:44:16 -05:00
```text
2023-02-28 03:35:24 -05:00
kind: 9
2023-02-28 03:41:01 -05:00
content: <reason for voting> // Can be empty string
tag: poll_r // for poll response
options:
- [<choices>]: array of index of the option | the first option is 0
2023-02-28 03:35:24 -05:00
```
#### Example - Vote
2023-01-05 14:17:12 -05:00
```json
{
...
2023-02-28 03:35:24 -05:00
"kind": 9,
2023-01-05 14:17:12 -05:00
"tags": [
...
2023-02-28 03:41:01 -05:00
["e", "<event-id>"],
["poll_r", "0"],
// OR
["poll_r", "0", "2"]
2023-01-05 14:17:12 -05:00
...
],
2023-02-28 03:41:01 -05:00
"content": "reason for voting"
2023-01-05 14:17:12 -05:00
}
```
2023-02-28 03:35:24 -05:00
## Relay and client recommendations
- Options should be limited to 4 options and should not display more than **4 options** in the poll
- Each option should be 25 chars limited
- Clients should display poll options if more than **one option** is present in the poll
- Clients should ignore vote events if the poll is **expired**
- Clients should not display more than one poll per message. The first poll in the message should be displayed.
2023-02-28 03:41:01 -05:00
- Poll title should be displayed if present and should be limited to 25 chars
2023-02-28 03:35:24 -05:00
## Warning
2023-01-05 14:17:12 -05:00
Keep in mind that all votes are public and accessible to everyone.