nim-chat-poc/examples/bot_echo.nim

31 lines
839 B
Nim
Raw Normal View History

2025-09-26 18:41:11 -07:00
# run with `./build/bot_echo`
import chronicles
import chronos
import chat
2025-09-26 18:41:11 -07:00
import content_types
proc main() {.async.} =
let waku = initWakuClient(DefaultConfig())
2025-10-15 16:20:54 -07:00
let ident = createIdentity("EchoBot")
var chatClient = newClient(waku, ident)
2025-09-26 18:41:11 -07:00
2025-10-15 16:20:54 -07:00
chatClient.onNewMessage(proc(convo: Conversation, msg: ReceivedMessage) {.async.} =
2025-09-26 18:41:11 -07:00
info "New Message: ", convoId = convo.id(), msg= msg
discard await convo.sendMessage(msg.content)
2025-09-26 18:41:11 -07:00
)
chatClient.onNewConversation(proc(convo: Conversation) {.async.} =
info "New Conversation Initiated: ", convoId = convo.id()
discard await convo.sendMessage(initTextFrame("Hello!").toContentFrame().encode())
2025-09-26 18:41:11 -07:00
)
await chatClient.start()
info "EchoBot started"
info "Invite", link=chatClient.createIntroBundle().toLink()
when isMainModule:
waitFor main()
runForever()