diff --git a/web-chat/src/App.tsx b/web-chat/src/App.tsx
index c077016916..f0aecdc0ff 100644
--- a/web-chat/src/App.tsx
+++ b/web-chat/src/App.tsx
@@ -67,12 +67,28 @@ export default function App() {
}
});
+ const commandHandler = (cmd: string) => {
+ let commandResponse = 'internal error';
+ switch (cmd) {
+ case '/help':
+ commandResponse = '/help Display this help';
+ break;
+ default:
+ commandResponse = 'Unknown Command'
+ }
+
+ setState(({waku, messages}) => {
+ messages.push(new ChatMessage(new Date(), 'Command Response', commandResponse));
+ return {waku, messages};
+ })
+ }
+
return (
diff --git a/web-chat/src/Room.tsx b/web-chat/src/Room.tsx
index 59efac061a..a045331698 100644
--- a/web-chat/src/Room.tsx
+++ b/web-chat/src/Room.tsx
@@ -15,6 +15,7 @@ import { useWaku } from './WakuContext';
interface Props {
lines: ChatMessage[],
+ commandHandler: (cmd: string) => void;
}
export default function Room (props :Props) {
@@ -26,9 +27,13 @@ export default function Room (props :Props) {
}
const sendMessage = async () => {
- const chatMessage = new ChatMessage(new Date(), 'web-chat', messageToSend);
- const wakuMsg = WakuMessage.fromBytes(chatMessage.encode(), ChatContentTopic);
- await waku!.relay.send(wakuMsg);
+ if (messageToSend.startsWith('/')) {
+ props.commandHandler(messageToSend)
+ } else {
+ const chatMessage = new ChatMessage(new Date(), 'web-chat', messageToSend);
+ const wakuMsg = WakuMessage.fromBytes(chatMessage.encode(), ChatContentTopic);
+ await waku!.relay.send(wakuMsg);
+ }
}
return (