nim-chat-poc/examples/bot_echo.nim
Jazz Turner-Baggs 0d171d9a43 Fix BotEcho
2025-10-20 08:21:31 -07:00

35 lines
960 B
Nim

# 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: ReceivedMessage) {.async.} =
info "New Message: ", convoId = convo.id(), msg= msg
discard await convo.sendMessage(chatClient.ds, msg.content)
)
chatClient.onNewConversation(proc(convo: Conversation) {.async.} =
info "New Conversation Initiated: ", convoId = convo.id()
discard 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()