-
Notifications
You must be signed in to change notification settings - Fork 1
nosgraph
nosgraph is a recommendation service for the Nostr network. It allows users to get personalized recommendations based on who they follow. This wiki page guides you through the process of using the nosgraph service to get user recommendations.
To perform these operations, you will need:
- cURL: A command-line tool used for transferring data specified with URL syntax.
Follow these steps to get recommendations for a user:
First, you need to fetch the followers of the user. This can be done by making a GET request to https://nostr.social/.well-known/nostr/pubkey/<pubkey>/index.json.
Use the following cURL command to fetch the followers:
curl https://nostr.social/.well-known/nostr/pubkey/de7ecd1e2976a6adb2ffa5f4db81a7d812c8bb6698aa00dcf1e76adb55efd645/index.jsonThis will return a JSON object with the user's details, including their followers. The followers can be found in the mainEntity.follows field. Each follower is represented as nostr:pubkey:<pubkey>.
{
"license": "You may use this data under the CC BY-NC-ND 4.0 license. Contact hi at [this API's domain, just without api] for licensing",
"quality": 2.5,
"recommendations": [
[
"04ea4f8350f1562aa1d60dc070561f5bb8386a11d1a00570fd7440da210e1713",
99.99657498771462
],
[
"9702521faeb9ca739322064d7acd01bd9b264a34e7d1b1ae5497594074f4a50f",
99.99544150585237
],
[
"1247900e20c96383b277b66949dabe31675c409ce8387b06c43abc2f06c06c25",
99.99539532223616
],
[
"f428971975cdb80d7c06e425309a6c1da3f35c4360c1f89f9895df9c1f80bfd3",
99.9951561443117
],
[
"638384700918e6a472477045dbcc229362ac0e64a48d927c48af609a956b9348",
99.99487245066041
],
[
"3e4d7867b8923ffca8349202d9c0e3a601bb021b720b5dc1bf548b5c868ea180",
99.99478523663952
],
[
"3b9c6fff4412f638162c13bd0e4a14ebe02e60b7f7f10d6298df085be5d53aa7",
99.9947002847761
],
[
"3da857d384e0e440f188a387215e256295e3f7d1ff76060c8c39db2231d8689b",
99.9946914283973
],
[
"f1b1a67893df63873d008f940d13c716f36230367003c1701b388246a29ba86c",
99.99463120490411
],
[
"0ab0fc3bc90939fd21db2ada417b0b7cad3b7b07f1a96d4ceb807892ddf913bd",
99.99456921602346
],
[
"2b67a93f08f5d74ee506191768f54559428043d298c7386ebb2cd0b5863b7dbf",
99.99440761812778
],
[
"32288b45803d6a2cf5226cdfa52e94c393c744a9775693f7bd2d7cb02ce90dc2",
99.99434178751288
],
[
"c6b2cbf389e4d94746d01509ef81208cc5bad36ae39602a42745e6c4f7fc5077",
99.99432273628732
],
[
"b52cc839ac79c6ebe09d5bf7136b15c4fe9188f04ad483d4c4e001c8e0492cc4",
99.99426053837429
],
[
"7ab79bc0f4a89de7d4c3d4236189d986c9e19d3da30dd1e899e4441d9385ad99",
99.99422216704428
],
[
"059d6b5d8d45ba8fb8be3573131114e0ac828e2558e7cc192f5b2ed9d68ea8a5",
99.99418147478659
],
[
"29731c4be607c34e2d427f20f2e6afcd4f6fb588743fbf1a1c99c32cc4af2a08",
99.99417717595516
],
[
"d6171a667a6198b75785c7d473ee4b43a94b9036aeebe05f8973ff5d01343a1c",
99.99407664152949
],
[
"0a31839d2f40d0ed0c71068a12b90d0ccc282cfdcc90695c8af341bf4a7d36b8",
99.99395496099794
],
[
"08b12391308d8ca5dd7208a3d40d4ea577455985ea8b18c36022f53d5940fc7a",
99.9939529356286
]
]
}After fetching the followers, you can now get recommendations. To do this, make a POST request to https://api.semisol.dev/nosgraph/v1/recommend with a JSON body containing:
-
pubkey: The public key of the user. -
following: The list of public keys that the user is following. Each public key should be in the formatpubkey:<pubkey>(extracted fromnostr:pubkey:<pubkey>). -
exclude: An optional list of public keys to exclude from the recommendations.
Use the following cURL command to get recommendations:
curl -X POST https://api.semisol.dev/nosgraph/v1/recommend -H "Content-Type: application/json" -d '{
"pubkey": "de7ecd1e2976a6adb2ffa5f4db81a7d812c8bb6698aa00dcf1e76adb55efd645",
"following": ["f728d9e6e7048358e70930f5ca64b097770d989ccd86854fe618eda9c8a38106","1907c92a96deaca8830b533fe0974e08ffa8e69ce51d8d53268ff9cd2b6c27af","c4eabae1be3cf657bc1855ee05e69de9f059cb7a059227168b80b89761cbc4e0"],
"exclude": []
}'This will return a JSON object containing the license, quality of the recommendations, and an array of recommended public keys with their relevance scores.
Example response:
{
"license": "CC BY-SA 4.0",
"quality": 85,
"recommendations": [
["pubkey6", 0.95],
["pubkey7", 0.90],
["pubkey8", 0.85]
]
}The recommendations field contains an array of pairs, where each pair is a public key and a relevance score. The relevance score can be used to sort the recommendations.
Here's an example using curl and jq (a command-line JSON processor) that chains these two requests together. This assumes that you are on a Unix-like system such as Linux or macOS:
# Fetch followers
followers=$(curl -s https://nostr.social/.well-known/nostr/pubkey/de7ecd1e2976a6adb2ffa5f4db81a7d812c8bb6698aa00dcf1e76adb55efd645/index.json | jq -r '.mainEntity.following[] | sub("nostr:pubkey:"; "")' | tr '\n' ',' | sed 's/,$//')
# Get recommendations
curl -X POST https://api.semisol.dev/nosgraph/v1/recommend \
-H "Content-Type: application/json" \
-d '{
"pubkey": "de7ecd1e2976a6adb2ffa5f4db81a7d812c8bb6698aa00dcf1e76adb55efd645",
"following": ["'"$followers"'"],
"exclude": []
}'The first command fetches the followers of the given user, extracts the public keys with jq, removes the nostr:pubkey: prefix, and turns the list of public keys into a comma-separated string.
The second command sends a POST request to the recommendation API with the public key of the user and the list of followers.
Please replace the public key with the actual public key you want to use.
Note: This script assumes that jq is installed on your system. If you don't have jq installed, you can install it using your package manager (apt-get install jq, brew install jq, etc.).
That's it! Now you know how to fetch a user's followers and get recommendations for that user using nosgraph. Happy networking on the Nostr network!
Thank you for visiting our project's wiki! We hope you found the information useful. If you have any questions or suggestions, please feel free to open an issue or submit a pull request. We appreciate your contribution and support!