logos-chat/src/nim_chat_poc.nim

72 lines
1.9 KiB
Nim
Raw Normal View History

2025-08-15 07:31:19 -07:00
import chronos
import chronicles
2025-08-22 18:45:55 -07:00
import strformat
2025-08-21 12:35:55 -07:00
import chat_sdk/client
2025-08-22 18:45:55 -07:00
import chat_sdk/conversations
2025-08-21 12:35:55 -07:00
import chat_sdk/delivery/waku_client
2025-08-22 18:45:55 -07:00
import chat_sdk/utils
2025-07-05 14:54:19 -07:00
2025-08-15 07:31:19 -07:00
proc initLogging() =
when defined(chronicles_runtime_filtering):
setLogLevel(LogLevel.Debug)
discard setTopicState("waku filter", chronicles.Normal, LogLevel.Error)
discard setTopicState("waku relay", chronicles.Normal, LogLevel.Error)
discard setTopicState("chat client", chronicles.Enabled, LogLevel.Debug)
2025-08-15 07:31:19 -07:00
proc main() {.async.} =
2025-08-15 07:31:19 -07:00
# Create Configurations
var cfg_saro = DefaultConfig()
var cfg_raya = DefaultConfig()
2025-08-15 07:31:19 -07:00
# Cross pollinate Peers
cfg_saro.staticPeers.add(cfg_raya.getMultiAddr())
cfg_raya.staticPeers.add(cfg_saro.getMultiAddr())
2025-08-15 07:31:19 -07:00
info "CFG", cfg = cfg_raya
info "CFG", cfg = cfg_saro
2025-08-15 07:31:19 -07:00
# Start Clients
var saro = newClient("Saro", cfg_saro)
2025-08-22 18:45:55 -07:00
saro.onNewMessage(proc(convo: Conversation, msg: string) {.async.} =
echo " Saro <------ :: " & msg
await sleepAsync(10000)
await convo.sendMessage(saro.ds, "Ping"))
2025-08-15 07:31:19 -07:00
await saro.start()
2025-08-15 07:31:19 -07:00
var raya = newClient("Raya", cfg_raya)
2025-08-22 18:45:55 -07:00
raya.onNewMessage(proc(convo: Conversation, msg: string) {.async.} =
echo " ------> Raya :: " & msg
await sleepAsync(10000)
await convo.sendMessage(raya.ds, "Pong"))
2025-08-15 07:31:19 -07:00
await raya.start()
2025-08-15 07:31:19 -07:00
await sleepAsync(5000)
2025-08-15 07:31:19 -07:00
# Perform OOB Introduction: Raya -> Saro
let raya_bundle = raya.createIntroBundle()
discard await saro.newPrivateConversation(raya_bundle)
2025-07-05 14:54:19 -07:00
2025-08-22 18:45:55 -07:00
await sleepAsync(5000)
try:
for convo in raya.listConversations():
notice " Convo", convo = convo.id()
await convo.sendMessage(raya.ds, "Hello")
# Let messages process
except Exception as e:
panic("UnCaught Exception"&e.msg)
2025-08-15 07:31:19 -07:00
await sleepAsync(400000)
2025-07-05 14:54:19 -07:00
2025-08-15 07:31:19 -07:00
saro.stop()
raya.stop()
2025-07-05 14:54:19 -07:00
2025-08-15 07:31:19 -07:00
when isMainModule:
initLogging()
waitFor main()
notice "Shutdown"