Skip to content

Commit b29dc3d

Browse files
fix: Use correct types in signatures of before,after and postMessage (#185)
Use correct types in signatures of before,after and postMessage
2 parents f4b86da + a13cd05 commit b29dc3d

File tree

6 files changed

+32
-24
lines changed

6 files changed

+32
-24
lines changed

lib/index.d.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
import Botkit = require('botkit');
17-
import AssistantV1 = require('ibm-watson/assistant/v1');
17+
import { MessageParams, MessageResponse } from 'ibm-watson/assistant/v1';
1818
import { Context } from 'ibm-watson/assistant/v1';
1919
import { BotkitMessage } from 'botkit';
2020
export interface WatsonMiddlewareConfig {
@@ -32,11 +32,12 @@ export interface WatsonMiddlewareConfig {
3232
iam_url?: string;
3333
minimum_confidence?: number;
3434
}
35-
export interface Payload extends AssistantV1.MessageRequest {
36-
workspace_id: string;
37-
}
35+
/**
36+
* @deprecated please use AssistantV1.MessageParams instead
37+
*/
38+
export declare type Payload = MessageParams;
3839
export declare type BotkitWatsonMessage = BotkitMessage & {
39-
watsonData?: Payload;
40+
watsonData?: MessageResponse;
4041
watsonError?: string;
4142
};
4243
export interface ContextDelta {
@@ -50,8 +51,8 @@ export declare class WatsonMiddleware {
5051
private readonly ignoreType;
5152
constructor(config: WatsonMiddlewareConfig);
5253
hear(patterns: string[], message: Botkit.BotkitMessage): boolean;
53-
before(message: Botkit.BotkitMessage, payload: Payload): Promise<Payload>;
54-
after(message: Botkit.BotkitMessage, response: any): Promise<any>;
54+
before(message: Botkit.BotkitMessage, payload: MessageParams): Promise<MessageParams>;
55+
after(message: Botkit.BotkitMessage, response: MessageResponse): Promise<MessageResponse>;
5556
sendToWatson(bot: Botkit.BotWorker, message: Botkit.BotkitMessage, contextDelta: ContextDelta): Promise<void>;
5657
receive(bot: Botkit.BotWorker, message: Botkit.BotkitMessage): Promise<void>;
5758
interpret(bot: Botkit.BotWorker, message: Botkit.BotkitMessage): Promise<void>;

lib/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/utils.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
*/
1616
import { Storage } from 'botbuilder';
1717
import AssistantV1 = require('ibm-watson/assistant/v1');
18-
import { Context } from 'ibm-watson/assistant/v1';
19-
import { Payload } from './index';
18+
import { Context, MessageParams, MessageResponse } from 'ibm-watson/assistant/v1';
2019
export declare function readContext(userId: string, storage: Storage): Promise<Context | null>;
2120
export declare function updateContext(userId: string, storage: Storage, watsonResponse: {
2221
context: Context;
2322
}): Promise<{
2423
context: Context;
2524
}>;
26-
export declare function postMessage(conversation: AssistantV1, payload: Payload): Promise<AssistantV1.MessageResponse>;
25+
export declare function postMessage(conversation: AssistantV1, payload: MessageParams): Promise<MessageResponse>;

lib/utils.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
const debug = require('debug')('watson-middleware:index');
1919
import Botkit = require('botkit');
2020
import AssistantV1 = require('ibm-watson/assistant/v1');
21+
import { MessageParams, MessageResponse } from 'ibm-watson/assistant/v1';
2122
import { Context } from 'ibm-watson/assistant/v1';
2223
import { Storage } from 'botbuilder';
2324
import { readContext, updateContext, postMessage } from './utils';
@@ -40,12 +41,13 @@ export interface WatsonMiddlewareConfig {
4041
minimum_confidence?: number;
4142
}
4243

43-
export interface Payload extends AssistantV1.MessageRequest {
44-
workspace_id: string;
45-
}
44+
/**
45+
* @deprecated please use AssistantV1.MessageParams instead
46+
*/
47+
export type Payload = MessageParams;
4648

4749
export type BotkitWatsonMessage = BotkitMessage & {
48-
watsonData?: Payload;
50+
watsonData?: MessageResponse;
4951
watsonError?: string;
5052
};
5153

@@ -86,12 +88,15 @@ export class WatsonMiddleware {
8688

8789
public before(
8890
message: Botkit.BotkitMessage,
89-
payload: Payload,
90-
): Promise<Payload> {
91+
payload: MessageParams,
92+
): Promise<MessageParams> {
9193
return Promise.resolve(payload);
9294
}
9395

94-
public after(message: Botkit.BotkitMessage, response: any): Promise<any> {
96+
public after(
97+
message: Botkit.BotkitMessage,
98+
response: MessageResponse,
99+
): Promise<MessageResponse> {
95100
return Promise.resolve(response);
96101
}
97102

@@ -128,7 +133,7 @@ export class WatsonMiddleware {
128133
try {
129134
const userContext = await readContext(message.user, this.storage);
130135

131-
const payload: Payload = {
136+
const payload: MessageParams = {
132137
// eslint-disable-next-line @typescript-eslint/camelcase
133138
workspace_id: this.config.workspace_id,
134139
};

src/utils.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
const debug = require('debug')('watson-middleware:utils');
1919
import { Storage } from 'botbuilder';
2020
import AssistantV1 = require('ibm-watson/assistant/v1');
21-
import { Context } from 'ibm-watson/assistant/v1';
22-
import { Payload } from './index';
21+
import {
22+
Context,
23+
MessageParams,
24+
MessageResponse,
25+
} from 'ibm-watson/assistant/v1';
2326

2427
const storagePrefix = 'user.';
2528

@@ -78,8 +81,8 @@ export async function updateContext(
7881

7982
export async function postMessage(
8083
conversation: AssistantV1,
81-
payload: Payload,
82-
): Promise<AssistantV1.MessageResponse> {
84+
payload: MessageParams,
85+
): Promise<MessageResponse> {
8386
debug('Assistant Request: %s', JSON.stringify(payload, null, 2));
8487
const response = await conversation.message(payload);
8588
debug('Assistant Response: %s', JSON.stringify(response, null, 2));

0 commit comments

Comments
 (0)