add bot example, add legacy code for nip04 support (on lifeline)

This commit is contained in:
Believethehype
2024-09-25 10:21:30 +02:00
parent 882dba0f2c
commit f7c4f718d3
16 changed files with 213 additions and 35 deletions

View File

@@ -28,7 +28,7 @@
"lnbits_admin_key = \"\" #TODO set your key here\n",
"lnbits_wallet_id = \"\" #TODO set your key here\n",
"lnbits_host= \"https://demo.lnbits.com\" #TODO you can use demo.lnbits.com, but rather use your own instance\n",
"nostdress_domain = \"nostrdvm.com\" #TODO use your own nostdress instance, or use the default one"
"nostdress_domain = \"nostrdvm.com\" # use your own nostdress instance, or use the default one"
],
"id": "2e71e7aa2ebdac50"
},

View File

@@ -35,8 +35,15 @@ def run_dvm(identifier):
name = "My very first DVM"
# Next we initalize a GenericDVM with the name and the dvm_config and the options we just created, as well as
# an empty AdminConfig() and NIP89Config(). We will check these out in later tutorials, so don't worry about them now.
# We add an admin config. By configuring it we can perform certain tasks, for example on start of the DVM
admin_config = AdminConfig()
# We broadcast our NIP65 inbox relays so other clients know where to write to so we receive it
admin_config.REBROADCAST_NIP65_RELAY_LIST = True
dvm = GenericDVM(name=name, dvm_config=dvm_config, options=options,
nip89config=NIP89Config(), admin_config=AdminConfig())
nip89config=NIP89Config(), admin_config=admin_config)
# Normally we would define the dvm interface as we do in the tasks folder (we will do it later in the tutorials as well,

View File

@@ -0,0 +1,68 @@
# In tutorial 2 we have written a very simplistic DVM that replies with "The result of the DVM is: #RunDVM"
# In tutorial 3 we have written a client that requests a response from the DVM and gets the reply back.
# In this tutorial we build a simple bot that bridges the communication between the user and the Kind 5050
# (Text generation) DVM.
import asyncio
import os
import threading
from pathlib import Path
import dotenv
from nostr_dvm.bot import Bot
from nostr_dvm.tasks.generic_dvm import GenericDVM
from nostr_sdk import Kind, Keys
from nostr_dvm.utils.admin_utils import AdminConfig
from nostr_dvm.utils.dvmconfig import build_default_config, DVMConfig
from nostr_dvm.utils.nip89_utils import NIP89Config
from nostr_dvm.utils.zap_utils import change_ln_address
def run_dvm(identifier):
identifier = "bot_test"
bot_config = build_default_config(identifier)
# The main purpose is of the Bot is to be an indexable overview of multiple DVMs. But we will use it in "chatbot" mode here
# by setting the CHATBOT option to true
bot_config.CHATBOT = True
# And we simply hand over the publickey of our DVM from tutorial 1
bot_config.DVM_KEY = "aa8ab5b774d47e7b29a985dd739cfdcccf93451678bf7977ba1b2e094ecd8b30" # TODO replace with your DVM
# We update our relay list and profile and Start the bot
admin_config = AdminConfig()
admin_config.REBROADCAST_NIP65_RELAY_LIST = True
admin_config.UPDATE_PROFILE = True
x = threading.Thread(target=Bot, args=([bot_config, admin_config]))
x.start()
# Now you can copy the npub to a Social client of your choice and (if tutorials 2 and 4 are running) it should reply
# in your client.
if __name__ == '__main__':
#We open the .env file we created before.
env_path = Path('.env')
if not env_path.is_file():
with open('.env', 'w') as f:
print("Writing new .env file")
f.write('')
if env_path.is_file():
print(f'loading environment from {env_path.resolve()}')
dotenv.load_dotenv(env_path, verbose=True, override=True)
else:
raise FileNotFoundError(f'.env file not found at {env_path} ')
# Replace the identifier with the one from the last notebook, or a new dvmconfig will be stored
identifier = "tutorial01"
# psst, you can change your lightning address here:
#asyncio.run(change_ln_address(identifier, "test", DVMConfig(), True))
run_dvm(identifier)