diff --git a/Makefile b/Makefile index 482c89b..3d9d941 100644 --- a/Makefile +++ b/Makefile @@ -87,9 +87,10 @@ nim_chat_poc: | build-waku-librln build-waku-nat nim_chat_poc.nims \ $(ENV_SCRIPT) nim nim_chat_poc $(NIM_PARAMS) nim_chat_poc.nims -tui: | build-waku-librln build-waku-nat nim_chat_poc.nims +# Ensure there is a nimble task with a name that matches the target +tui bot_echo: | build-waku-librln build-waku-nat nim_chat_poc.nims echo -e $(BUILD_MSG) "build/$@" && \ - $(ENV_SCRIPT) nim tui $(NIM_PARAMS) --path:src nim_chat_poc.nims + $(ENV_SCRIPT) nim $@ $(NIM_PARAMS) --path:src nim_chat_poc.nims endif diff --git a/examples/bot_echo.nim b/examples/bot_echo.nim new file mode 100644 index 0000000..4a85108 --- /dev/null +++ b/examples/bot_echo.nim @@ -0,0 +1,35 @@ +# run with `./build/bot_echo` + +import chronicles +import chronos + +import chat_sdk +import content_types + +import ./tui/persistence # Temporary Workaround for PeerDiscovery + +proc main() {.async.} = + + let cfg = await getCfg("EchoBot") + # let dsConfig = DefaultConfig() + # let ident = createIdentity("EchoBot") + var chatClient = newClient(dsConfig, ident) + + chatClient.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} = + info "New Message: ", convoId = convo.id(), msg= msg + await convo.sendMessage(chatClient.ds, msg) + ) + + chatClient.onNewConversation(proc(convo: Conversation) {.async.} = + info "New Conversation Initiated: ", convoId = convo.id() + await convo.sendMessage(chatClient.ds, initTextFrame("Hello!").toContentFrame()) + ) + + await chatClient.start() + + info "EchoBot started" + info "Invite", link=chatClient.createIntroBundle().toLink() + +when isMainModule: + waitFor main() + runForever() \ No newline at end of file diff --git a/examples/nim_chat_poc.nim b/examples/nim_chat_poc.nim index 9a3c480..0baf44d 100644 --- a/examples/nim_chat_poc.nim +++ b/examples/nim_chat_poc.nim @@ -66,7 +66,7 @@ proc main() {.async.} = saro.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} = echo " Saro <------ :: " & getContent(msg) await sleepAsync(10000) - await convo.sendMessage(saro.ds, initImage( + discard await convo.sendMessage(saro.ds, initImage( "https://waku.org/theme/image/logo-black.svg")) ) @@ -80,12 +80,12 @@ proc main() {.async.} = raya.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} = echo " ------> Raya :: " & getContent(msg) await sleepAsync(10000) - await convo.sendMessage(raya.ds, initTextFrame("Pong").toContentFrame()) + discard await convo.sendMessage(raya.ds, initTextFrame("Pong").toContentFrame()) ) raya.onNewConversation(proc(convo: Conversation) {.async.} = echo " ------> Raya :: New Conversation: " & convo.id() - await convo.sendMessage(raya.ds, initTextFrame("Hello").toContentFrame()) + discard await convo.sendMessage(raya.ds, initTextFrame("Hello").toContentFrame()) ) raya.onDeliveryAck(proc(convo: Conversation, msgId: string) {.async.} = echo " raya -- Read Receipt for " & msgId