Skip to content

Commit

Permalink
link message prototype (#19)
Browse files Browse the repository at this point in the history
* add receive and send link prototype

* refactor UrlPayload related code to support wechaty/wechaty#1539

* 0.13.1

* add url

* 0.13.2

* fix pack testing

* 0.13.3

* upgrade typescript 3

* 0.13.4

* vscode config clean

* 0.13.5
  • Loading branch information
windmemory authored and huan committed Aug 10, 2018
1 parent 31040b5 commit 15861a0
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 21 deletions.
23 changes: 9 additions & 14 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
{
"typescript.tsdk": "./node_modules/typescript/lib"
, "update.channel": "none"
, "files.exclude": {
"node_modules/": true
, "package/": true
}
, "alignment": {
"operatorPadding": "right"
, "indentBase": "firstline"
, "surroundSpace": {
"typescript.tsdk": "./node_modules/typescript/lib",
"files.exclude": {
"node_modules/": true,
"package/": true
},
"alignment": {
"operatorPadding": "right",
"indentBase": "firstline",
"surroundSpace": {
"colon": [1, 1], // The first number specify how much space to add to the left, can be negative. The second number is how much space to the right, can be negative.
"assignment": [1, 1], // The same as above.
"arrow": [1, 1], // The same as above.
"comment": 2 // Special how much space to add between the trailing comment and the code.
// If this value is negative, it means don't align the trailing comment.
}
}
, "eslint.autoFixOnSave": false
, "tslint.autoFixOnSave": false
, "editor.formatOnSave": false
, "typescript.extension.sortImports.sortOnSave": false
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wechaty-puppet",
"version": "0.11.6",
"version": "0.13.5",
"description": "Abstract Puppet for Wechaty",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand Down Expand Up @@ -58,7 +58,7 @@
"tslint-config-standard": "^7.1.0",
"typedoc": "^0.11.1",
"typedoc-plugin-markdown": "^1.1.13",
"typescript": "^2.9.2"
"typescript": "^3.0.1"
},
"git": {
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export {
export {
RoomInvitationPayload,
} from './schemas/room-invitation'
export {
UrlPayload,
} from './schemas/url'

export {
PuppetOptions,
Expand Down
8 changes: 7 additions & 1 deletion src/puppet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import {
import {
RoomInvitationPayload,
} from './schemas/room-invitation'
import {
UrlPayload,
} from './schemas/url'

import {
Receiver,
Expand Down Expand Up @@ -97,11 +100,14 @@ class PuppetTest extends Puppet {
* Message
*
*/
public async messageFile (messageId: string) : Promise<FileBox> { return { messageId } as any }
public async messageFile (messageId: string) : Promise<FileBox> { return { messageId } as any }
public async messageUrl (messageId: string) : Promise<UrlPayload> { return { messageId } as any }

public async messageForward (to: Receiver, messageId: string) : Promise<void> { return { to, messageId } as any }
public async messageSendContact (receiver: Receiver, contactId: string) : Promise<void> { return { receiver, contactId } as any }
public async messageSendFile (to: Receiver, file: FileBox) : Promise<void> { return { to, file } as any }
public async messageSendText (to: Receiver, text: string) : Promise<void> { return { to, text } as any }
public async messageSendUrl (to: Receiver, urlPayload: UrlPayload) : Promise<void> { return { to, urlPayload } as any }

public async messageRawPayload (id: string) : Promise<any> { return { id } as any }
public async messageRawPayloadParser (rawPayload: any) : Promise<MessagePayload> { return { rawPayload } as any }
Expand Down
8 changes: 7 additions & 1 deletion src/puppet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ import {
import {
RoomInvitationPayload,
} from './schemas/room-invitation'
import {
UrlPayload,
} from './schemas/url'

import {
PuppetEventName,
Expand Down Expand Up @@ -747,11 +750,14 @@ export abstract class Puppet extends EventEmitter {
* Message
*
*/
public abstract async messageFile (messageId: string) : Promise<FileBox>
public abstract async messageFile (messageId: string) : Promise<FileBox>
public abstract async messageUrl (messageId: string) : Promise<UrlPayload>

public abstract async messageForward (receiver: Receiver, messageId: string) : Promise<void>
public abstract async messageSendText (receiver: Receiver, text: string) : Promise<void>
public abstract async messageSendContact (receiver: Receiver, contactId: string) : Promise<void>
public abstract async messageSendFile (receiver: Receiver, file: FileBox) : Promise<void>
public abstract async messageSendUrl (receiver: Receiver, urlPayload: UrlPayload): Promise<void>

protected abstract async messageRawPayload (messageId: string) : Promise<any>
protected abstract async messageRawPayloadParser (rawPayload: any) : Promise<MessagePayload>
Expand Down
7 changes: 5 additions & 2 deletions src/schemas/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ export enum WechatMessageType {
/** @hidden */
export interface MessagePayloadBase {
id : string,
contactId? : string, // Contact ShareCard
filename? : string,

// use message id to get rawPayload to get those informations when needed
// contactId? : string, // Contact ShareCard
// filename? : string,

text? : string,
timestamp : number, // Unix Timestamp(in seconds)
type : MessageType,
Expand Down
6 changes: 6 additions & 0 deletions src/schemas/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface UrlPayload {
description? : string,
thumbnailUrl? : string,
title : string,
url : string,
}
6 changes: 5 additions & 1 deletion tests/fixtures/smoke-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
RoomPayload,
RoomQueryFilter,

UrlPayload,
} from 'wechaty-puppet'

import {
Expand Down Expand Up @@ -85,11 +86,14 @@ class PuppetTest extends Puppet {
* Message
*
*/
public async messageFile (messageId: string) : Promise<FileBox> { return { messageId } as any }
public async messageFile (messageId: string) : Promise<FileBox> { return { messageId } as any }
public async messageUrl (messageId: string) : Promise<UrlPayload> { return { messageId } as any }

public async messageForward (to: Receiver, messageId: string) : Promise<void> { return { to, messageId } as any }
public async messageSendContact (receiver: Receiver, contactId: string) : Promise<void> { return { receiver, contactId } as any }
public async messageSendFile (to: Receiver, file: FileBox) : Promise<void> { return { to, file } as any }
public async messageSendText (to: Receiver, text: string) : Promise<void> { return { to, text } as any }
public async messageSendUrl (to: Receiver, urlPayload: UrlPayload) : Promise<void> { return { to, urlPayload } as any }

public async messageRawPayload (id: string) : Promise<any> { return { id } as any }
public async messageRawPayloadParser (rawPayload: any) : Promise<MessagePayload> { return { rawPayload } as any }
Expand Down

0 comments on commit 15861a0

Please sign in to comment.