Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send MiniProgram using PadPro #172

Merged
merged 6 commits into from Jul 25, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -65,3 +65,5 @@ typings/
/*.png
/*.html
/*.memory-card.json

.idea
@@ -1,6 +1,6 @@
{
"name": "wechaty-puppet-padpro",
"version": "0.3.9",
"version": "0.3.10",
"description": "Padpro Puppet for Wechaty",
"directories": {
"example": "examples"
@@ -65,11 +65,11 @@
"qrcode-terminal": "^0.12.0",
"shx": "^0.3.1",
"tstest": "^0.4.2",
"wechaty-puppet": "^0.15.21"
"wechaty-puppet": "^0.15.25"
},
"peerDependencies": {
"file-box": "^0.8.27",
"wechaty-puppet": "^0.15.1"
"wechaty-puppet": "^0.15.25"
},
"homepage": "https://github.com/botorange/wechaty-puppet-padpro#readme",
"dependencies": {
@@ -43,6 +43,7 @@ import {
RoomPayload,

UrlLinkPayload,
MiniProgramPayload,
} from 'wechaty-puppet'

import {
@@ -59,6 +60,7 @@ import {
friendshipVerifyEventMessageParser,

generateAppXMLMessage,
generateMiniProgramXMLMessage,
generateAttachmentXMLMessageFromRaw,

imagePayloadParser,
@@ -987,6 +989,27 @@ export class PuppetPadpro extends Puppet {
}
}

public async messageMiniProgram (messageId: string): Promise<MiniProgramPayload> {

const rawPayload = await this.messageRawPayload(messageId)
const payload = await this.messagePayload(messageId)

if (payload.type !== MessageType.MiniProgram) {
throw new Error('Can not get miniProgram from non miniProgram payload')
} else {
const appPayload = await appMessageParser(rawPayload)
if (appPayload) {
return {

This comment has been minimized.

Copy link
@windmemory

windmemory Jul 22, 2019

Member

What's the reason returning empty object here?

This comment has been minimized.

Copy link
@zhaoic

zhaoic Jul 25, 2019

Author Contributor

Is messageForward work well?
I tested with text , using 'msg.forward(contact)', it's not work!
I confirmed that code was step into messageForward->this.messageSendText
receiver:

{ contactId: 'wxid_gjg27bv08vu612', roomId: undefined }

payload:

{ id: '1097670511',
  timestamp: 1564021102,
  type: 7,
  fromId: 'wxid_jy0q2q63aggm21',
  mentionIdList: undefined,
  roomId: undefined,
  text: 'hello world',
  toId: 'wxid_gjg27bv08vu612' }

image

description : appPayload.des,
title : appPayload.title,
// TODO: add miniProgram support in appMessageParser()
}
} else {
throw new Error('Can not parse miniProgram message payload')
}
}
}

public async messageRawPayload (id: string): Promise<PadproMessagePayload> {
const rawPayload = this.cachePadproMessagePayload.get(id)

@@ -1177,6 +1200,26 @@ export class PuppetPadpro extends Puppet {
await this.padproManager.GrpcSendApp(id, generateAppXMLMessage(urlLinkPayload))
}

public async messageSendMiniProgram (
receiver: Receiver,
miniProgramPayload: MiniProgramPayload
): Promise<void> {
log.verbose(PRE, `messageSendMiniProgram("${JSON.stringify(receiver)}", ${JSON.stringify(miniProgramPayload)})`)

if (!this.padproManager) {
throw new Error('no padpro manager')
}

// Send to the Room if there's a roomId
const id = receiver.roomId || receiver.contactId

if (!id) {
throw Error('no id')
}

await this.padproManager.GrpcSendApp(id, generateMiniProgramXMLMessage(miniProgramPayload))
}

public async messageForward (
receiver : Receiver,
messageId : string,
@@ -1229,6 +1272,12 @@ export class PuppetPadpro extends Puppet {
receiver,
await this.messageUrl(messageId)
)
} else if (payload.type === MessageType.MiniProgram) {
// TODO: currently this strips out the app information
await this.messageSendMiniProgram(
receiver,
await this.messageMiniProgram(messageId)
)
} else if (payload.type === MessageType.Video) {
await this.forwardVideo(receiver, messageId)
// commenting this out because currently there is no way to directly send location
@@ -1,4 +1,4 @@
import { UrlLinkPayload } from 'wechaty-puppet'
import { UrlLinkPayload, MiniProgramPayload } from 'wechaty-puppet'
import { PadproAppMessagePayload, PadproLocationMessagePayload, WechatAppMessageType } from '../schemas'

export const generateLocationMessage = (payload: PadproLocationMessagePayload): string => {
@@ -24,6 +24,65 @@ export const generateAppXMLMessage = ({ title, description, url, thumbnailUrl }:
+ `</appmsg>`
}

export const generateMiniProgramXMLMessage = (payload: MiniProgramPayload): string => {
return `
<appmsg appid="" sdkver="0">
<title>${payload.title}</title>
<des>${payload.description}</des>
<action/>
<type>33</type>
<showtype>0</showtype>
<soundtype>0</soundtype>
<mediatagname/>
<messageext/>
<messageaction/>
<content/>
<contentattr>0</contentattr>
<url>https://mp.weixin.qq.com/mp/waerrpage?appid=${payload.appid}&amp;type=upgrade&amp;upgradetype=3#wechat_redirect</url>
<lowurl/>
<dataurl/>
<lowdataurl/>
<appattach>
<totallen>0</totallen>
<attachid/>
<emoticonmd5/>
<fileext/>
<cdnthumburl></cdnthumburl>
<cdnthumbmd5></cdnthumbmd5>
<cdnthumblength></cdnthumblength>
<cdnthumbwidth></cdnthumbwidth>
<cdnthumbheight></cdnthumbheight>
<cdnthumbaeskey></cdnthumbaeskey>
<aeskey></aeskey>
<encryver>0</encryver>
<filekey></filekey>
</appattach>
<extinfo/>
<sourceusername>${payload.username}@app</sourceusername>
<sourcedisplayname>${payload.description}</sourcedisplayname>
<thumburl/>
<md5/>
<statextstr/>
<weappinfo>
<username><![CDATA[${payload.username}@app]]></username>
<appid><![CDATA[${payload.appid}]]></appid>
<type>2</type>
<version></version>
<weappiconurl><![CDATA[]]></weappiconurl>
<pagepath><![CDATA[${payload.pagepath}]]></pagepath>
<shareId><![CDATA[0_${payload.appid}_858901320_1563444358_0]]></shareId>
<appservicetype>0</appservicetype>
</weappinfo>
</appmsg>
<fromusername></fromusername>
<scene>0</scene>
<appinfo>
<version>1</version>
<appname/>
</appinfo>
<commenturl/>`
}

export const generateAttachmentXMLMessageFromRaw = (payload: PadproAppMessagePayload): string => {
return `
<appmsg appid="" sdkver="0">
@@ -238,6 +238,7 @@ export async function messageRawPayloadParser (
payload.type = MessageType.ChatHistory
break
case WechatAppMessageType.MiniProgram:
case WechatAppMessageType.MiniProgramApp:
payload.type = MessageType.MiniProgram
break
case WechatAppMessageType.RedEnvelopes:
@@ -97,6 +97,7 @@ export enum WechatAppMessageType {
RealtimeShareLocation = 17,
ChatHistory = 19,
MiniProgram = 33,
MiniProgramApp = 36, // this is forwardable mini program
Transfers = 2000,
RedEnvelopes = 2001,
ReaderType = 100001,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.