Compare commits

...

6 Commits

Author SHA1 Message Date
Fernando López Guevara cd51eb5f0f
Merge 10dc8223a6 into a551c5b693 2024-06-25 11:32:50 -04:00
Asai Toshiya a551c5b693 NIP-89: fix `REQ` examples 2024-06-25 12:17:39 -03:00
Fernando López Guevara 10dc8223a6
Merge branch 'master' into fr-surveys 2023-03-03 20:11:43 -03:00
Fernando López Guevara 1aa3ddf0e1 feat(surv): update nip & use parameterized replaceable events for surv-answer 2023-03-03 19:31:32 -03:00
Fernando López Guevara 44a886e119 NIP-41 2022-12-22 15:03:03 -03:00
Fernando López Guevara 64bb88c83d feat: add surveys / polls 2022-12-22 12:31:49 -03:00
3 changed files with 161 additions and 2 deletions

158
41.md Normal file
View File

@ -0,0 +1,158 @@
NIP-41
======
# Surveys / polls / quizzes
-----------------------------------
`draft` `optional` `require:nip-13` `require:nip-57` `author:fernandolguevara`
The `surv` tag & `surv-answer` (kind: `30041`) enables users to have surveys/polls/quizzes experiences on the network.
## Spec
### surv
To start a survey on the network, an event with one or many 'surv' tags may be created.
```json
{"tags":[
["surv", "{single|multiple}", "ttl", "(label)", "option 1", "option 2", "option 3", "option 4"]
["nonce", "1", "32"]
["amount", "milli-satoshi value"]
]}
```
#### tags
- `surv`:
- `{single|multiple}`: allow others to reply with single or multiple choice.
- `ttl:unix-time`: when survey expires, `0` don't expire.
- `(label):string`: if present, clients should use it as surv label.
- `option:string`: survey options
- `nonce`: if present, pow is mandatory for answer. ref: [13](13.md)
- `amount`: if present, zap is mandatory for answer. ref: [57](57.md)
### surv-answer
To reply to a survey on the network, an event of kind `30041` is created.
```meta
["surv-answer", "surv-index", "option-index", ...]
```
```json
{
"kind": 30041,
"tags":[
["e", "<event-id-root>", "wss://...", "root"]
["d", "surv-answer/{event-id-root}"]
["surv-answer", "0", "option-index:int", "{...}"]
["nonce", "1", "32"],
["amount", "milli-satoshi value"],
]
}
```
at least one selected option index should present on the answer event the tag `surv-answer`
tags:
- `e`: `<event-id-root>` origin event.
- `d`: the value should be an string formed using origin `event-id-root` for the survey.
- `surv-answer`:
- `surv-index:int`: starting at 0.
- `option-index:int`: starting at 0.
- `nonce`: if present, pow is mandatory for answer.
- `amount`: if present, zap is mandatory for answer.
## Relay and client recommendations
- `surv` tag:
- Should have at least `two` options.
- The value of the `label` field should allow enough characters to express the questions.
- The `options` items should be limited up to 4.
- Each `option` should be 25 chars limited.
## Examples
### Example surv single
```json
{
"pubkey": "<pub-key>",
"created_at": 1000000000,
"kind": 1,
"tags": [
["t", "hastag"],
["surv", "single", "0", "", "option 1", "option 2", "options 3"],
],
"content": "#hastag what is your favorite option?",
"id": "<event-id>"
},
{
"pubkey": "<pub-key>",
"created_at": 1000000000,
"kind": 30041,
"tags": [
["e", "<event-id-root>", "wss://...", "root"],
["t", "tag"],
["surv-answer", "", "0"]
],
"content": "here my favorite option is #option1 \n",
"id": "<event-id>"
}
```
### Example surv multiple with expiration
```json
{
"pubkey": "<pub-key>",
"created_at": 1000000000,
"kind": 1,
"tags": [
["t", "hastag"],
["surv", "multiple", "1684599600"],
["options", "option 1", "option 2", "options 3"],
],
"content": "#hastag what are your favorite options?",
"id": "<event-id>"
},
{
"pubkey": "<pub-key>",
"created_at": 1000000000,
"kind": 30041,
"tags": [
["e", "<event-id-root>", "wss://...", "root"],
["t", "tag"],
["surv-answer", "", "0", "2"]
],
"content": "here my favorite option is #option1 \n",
"id": "<event-id>"
}
```
### Example multiple surv
```json
{
"pubkey": "<pub-key>",
"created_at": 1000000000,
"kind": 1,
"tags": [
["t", "hastag"],
["surv", "single", "0", "surv 1?", "option 1", "option 2", "options 3"],
["surv", "multiple", "0", "surv 2?", "option 1", "option 2", "options 3"],
],
"content": "#hastag Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do?",
"id": "<event-id>"
},
{
"pubkey": "<pub-key>",
"created_at": 1000000000,
"kind": 30041,
"tags": [
["e", "<event-id-root>", "wss://...", "root"],
["surv-answer", "0", "0"]
["surv-answer", "1", "0", "2"]
],
"content": "quis nostrud exercitation ullamco laboris!\n",
"id": "<event-id>"
}
```

4
89.md
View File

@ -116,7 +116,7 @@ User B might see in their timeline an event referring to a `kind:31337` event (e
User B's client, not knowing how to handle a `kind:31337` might display the event using its `alt` tag (as described in NIP-31). When the user clicks on the event, the application queries for a handler for this `kind`:
```json
["REQ", <id>, '[{ "kinds": [31989], "#d": ["31337"], 'authors': [<user>, <users-contact-list>] }]']
["REQ", <id>, { "kinds": [31989], "#d": ["31337"], "authors": [<user>, <users-contact-list>] }]
```
User B, who follows User A, sees that `kind:31989` event and fetches the `a`-tagged event for the app and handler information.
@ -127,5 +127,5 @@ User B's client sees the application's `kind:31990` which includes the informati
Alternatively, users might choose to query directly for `kind:31990` for an event kind. Clients SHOULD be careful doing this and use spam-prevention mechanisms or querying high-quality restricted relays to avoid directing users to malicious handlers.
```json
["REQ", <id>, '[{ "kinds": [31990], "#k": [<desired-event-kind>], 'authors': [...] }]']
["REQ", <id>, { "kinds": [31990], "#k": [<desired-event-kind>], "authors": [...] }]
```

View File

@ -56,6 +56,7 @@ They exist to document what may be implemented by [Nostr](https://github.com/nos
- [NIP-38: User Statuses](38.md)
- [NIP-39: External Identities in Profiles](39.md)
- [NIP-40: Expiration Timestamp](40.md)
- [NIP-41: Surveys/Polls/Quizzes](41.md)
- [NIP-42: Authentication of clients to relays](42.md)
- [NIP-44: Versioned Encryption](44.md)
- [NIP-45: Counting results](45.md)