Skip to content
This repository has been archived by the owner on Dec 26, 2021. It is now read-only.

Fixed params types of send-methods #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/core/Bot.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IActivityStream } from '@broid/schemas';
import * as express from 'express';
import * as http from 'http';
import { Observable } from 'rxjs/Rx';
import { callbackType, IMetaMediaSend, IOptions, IMessage } from './interfaces';
import { callbackType, IMessage, IMetaMediaSend, IOptions, ISendData } from './interfaces';
export declare class Bot {
httpEndpoints: string[];
httpServer: http.Server | null;
Expand All @@ -20,9 +20,9 @@ export declare class Bot {
hear(pattern: string | boolean, messageTypes?: string | callbackType, cb?: callbackType): Observable<IMessage>;
hears(patterns: string[], messageTypes?: string | callbackType, cb?: callbackType): Observable<IActivityStream>;
on(messageTypes?: string | callbackType, cb?: callbackType): Observable<IMessage>;
sendText(text: string, message: IActivityStream): any;
sendVideo(url: string, message: IActivityStream, meta?: IMetaMediaSend): any;
sendImage(url: string, message: IActivityStream, meta?: IMetaMediaSend): any;
sendText(text: string, message: ISendData): any;
sendVideo(url: string, message: ISendData, meta?: IMetaMediaSend): any;
sendImage(url: string, message: ISendData, meta?: IMetaMediaSend): any;
private processOutgoingContent(content, message);
private messageTypes2Arr(messageTypes?);
private processArgs(msgTypes?, cb?);
Expand Down
16 changes: 15 additions & 1 deletion lib/core/interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IActivityStream } from '@broid/schemas';
import { IActivityStream, IASContext } from '@broid/schemas';
import { Observable } from 'rxjs/Rx';
export declare type callbackType = (message: any, error?: any) => any;
export declare type middlewareIncomingType = (bot: any, message: any, acc?: any) => Promise<any> | Observable<any>;
Expand All @@ -23,3 +23,17 @@ export interface IMessage {
data: any;
message: IActivityStream;
}
export interface ISendData {
generator: {
id: string;
name: string;
};
target: {
id: string;
type: string;
};
object?: {
id: string;
context: IASContext;
};
}
11 changes: 6 additions & 5 deletions src/core/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import {
callbackType,
IHTTPOptions,
IListenerArgs,
IMessage,
IMetaMediaSend,
IOptions,
IMessage,
ISendData,
middlewareIncomingType,
middlewareOutgoingType,
} from './interfaces';
Expand Down Expand Up @@ -149,7 +150,7 @@ export class Bot {
return this.hear(true, messageTypes, cb);
}

public sendText(text: string, message: IActivityStream) {
public sendText(text: string, message: ISendData) {
return this.processOutgoingContent(text, message)
.then((updated) => {
const content: string = updated.content || text;
Expand Down Expand Up @@ -178,11 +179,11 @@ export class Bot {
});
}

public sendVideo(url: string, message: IActivityStream, meta?: IMetaMediaSend) {
public sendVideo(url: string, message: ISendData, meta?: IMetaMediaSend) {
return this.sendMedia(url, 'Video', message, meta);
}

public sendImage(url: string, message: IActivityStream, meta?: IMetaMediaSend) {
public sendImage(url: string, message: ISendData, meta?: IMetaMediaSend) {
return this.sendMedia(url, 'Image', message, meta);
}

Expand Down Expand Up @@ -279,7 +280,7 @@ export class Bot {
}

private sendMedia(url: string, mediaType: string,
message: IActivityStream,
message: ISendData,
meta: IMetaMediaSend = {}): Promise<any> {
return this.processOutgoingContent(url, message)
.then((updated: any) => {
Expand Down
17 changes: 16 additions & 1 deletion src/core/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IActivityStream } from '@broid/schemas';
import { IActivityStream, IASContext } from '@broid/schemas';

import { Observable } from 'rxjs/Rx';

Expand Down Expand Up @@ -33,3 +33,18 @@ export interface IMessage {
data: any;
message: IActivityStream;
}

export interface ISendData {
generator: {
id: string;
name: string;
};
target: {
id: string;
type: string;
};
object?: {
id: string;
context: IASContext;
};
}