@wabot-dev/framework 0.9.21 → 0.9.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,6 +59,10 @@ let CmdChannel = class CmdChannel {
59
59
  injectInstances: [[Auth, this.auth]],
60
60
  });
61
61
  },
62
+ onClear: () => {
63
+ this.chatId = Random.alphaNumericLowerCase(10);
64
+ writeJsonToFile(this.chatIdPath(), this.chatId);
65
+ },
62
66
  });
63
67
  }
64
68
  routeSlug() {
@@ -151,6 +151,23 @@ let CmdChannelServer = class CmdChannelServer {
151
151
  });
152
152
  return;
153
153
  }
154
+ case 'clear': {
155
+ if (!this.activeRoute) {
156
+ this.sendToClient({ type: 'error', message: 'no channel selected' });
157
+ return;
158
+ }
159
+ const handlers = this.channels.get(this.activeRoute);
160
+ if (!handlers) {
161
+ this.sendToClient({ type: 'error', message: 'channel no longer available' });
162
+ this.activeRoute = null;
163
+ return;
164
+ }
165
+ if (handlers.onClear) {
166
+ await handlers.onClear();
167
+ }
168
+ this.sendToClient({ type: 'cleared', route: this.activeRoute });
169
+ return;
170
+ }
154
171
  }
155
172
  }
156
173
  sendToClient(msg) {
@@ -11,10 +11,11 @@ const green = ansi('1;32');
11
11
  const greenText = ansi('32');
12
12
  const red = ansi('1;31');
13
13
  const yellow = ansi('33');
14
- const COMMANDS = ['/channels', '/help', '/exit'];
14
+ const COMMANDS = ['/channels', '/clear', '/help', '/exit'];
15
15
  const HELP_LINES = [
16
16
  'Commands:',
17
17
  ' /channels list channels and switch',
18
+ ' /clear start a fresh conversation on the current channel',
18
19
  ' /help show this help',
19
20
  ' /exit quit',
20
21
  ];
@@ -96,6 +97,10 @@ function runCmdClient() {
96
97
  process.stdout.write(`\n${green(`[${msg.senderName ?? 'bot'}]:`)} ${greenText(msg.text)}\n\n`);
97
98
  rl.prompt();
98
99
  return;
100
+ case 'cleared':
101
+ process.stdout.write(green(`[conversation cleared on ${msg.route}]`) + '\n');
102
+ rl.prompt();
103
+ return;
99
104
  case 'error':
100
105
  process.stderr.write(red('error: ') + red(msg.message) + '\n');
101
106
  rl.prompt();
@@ -202,6 +207,15 @@ function runCmdClient() {
202
207
  send({ type: 'hello' });
203
208
  return;
204
209
  }
210
+ if (trimmed === '/clear') {
211
+ if (state !== 'chatting') {
212
+ process.stderr.write(red('select a channel before clearing the conversation.') + '\n');
213
+ rl.prompt();
214
+ return;
215
+ }
216
+ send({ type: 'clear' });
217
+ return;
218
+ }
205
219
  if (state === 'disconnected') {
206
220
  process.stderr.write(red('not connected to framework — waiting for server...') + '\n');
207
221
  rl.prompt();
@@ -2061,6 +2061,7 @@ interface ICmdChannelHandlers {
2061
2061
  senderName?: string;
2062
2062
  text: string;
2063
2063
  }) => void) => Promise<void> | void;
2064
+ onClear?: () => Promise<void> | void;
2064
2065
  }
2065
2066
  declare class CmdChannelServer {
2066
2067
  private server;
@@ -2123,6 +2124,8 @@ type CmdClientMessage = {
2123
2124
  } | {
2124
2125
  type: 'message';
2125
2126
  text: string;
2127
+ } | {
2128
+ type: 'clear';
2126
2129
  };
2127
2130
  type CmdServerMessage = {
2128
2131
  type: 'channels';
@@ -2134,6 +2137,9 @@ type CmdServerMessage = {
2134
2137
  type: 'reply';
2135
2138
  senderName?: string;
2136
2139
  text: string;
2140
+ } | {
2141
+ type: 'cleared';
2142
+ route: string;
2137
2143
  } | {
2138
2144
  type: 'error';
2139
2145
  message: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wabot-dev/framework",
3
- "version": "0.9.21",
3
+ "version": "0.9.22",
4
4
  "description": "Framework for IA Chat Bots",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",