Add EchoBot

This commit is contained in:
Jazz Turner-Baggs 2025-09-26 18:41:11 -07:00
parent da7bada6b3
commit 35274b6ec4
No known key found for this signature in database
3 changed files with 41 additions and 5 deletions

View File

@ -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

35
examples/bot_echo.nim Normal file
View File

@ -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()

View File

@ -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