Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-plugin-adapter-wecom
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
koishi-plugin-adapter-wecom
Commits
747d0148
Commit
747d0148
authored
Mar 17, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add wecom/message for not-supported custom messages
parent
71d0c6c9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
10 deletions
+14
-10
src/http.ts
src/http.ts
+3
-2
src/index.ts
src/index.ts
+3
-2
src/utils.ts
src/utils.ts
+8
-6
No files found.
src/http.ts
View file @
747d0148
...
...
@@ -3,6 +3,7 @@ import { AdapterConfig, dispatchSession } from './utils';
import
{
BotConfig
,
WeComBot
}
from
'
./bot
'
;
import
{
decrypt
,
getSignature
}
from
'
@wecom/crypto
'
;
import
{
WecomEventBody
,
WecomEventResponse
,
WecomReceiveMessageDto
,
WecomRegisterDto
,
...
...
@@ -67,7 +68,7 @@ export default class HttpServer extends Adapter<BotConfig, AdapterConfig> {
const
query
=
ctx
.
request
.
query
as
unknown
as
WecomReceiveMessageDto
;
const
rawData
=
(
await
rawBody
(
ctx
.
req
)).
toString
(
'
utf8
'
).
trim
();
const
{
xml
:
parsedData
}
=
(
await
this
.
xmlParser
.
parse
(
rawData
))
as
{
xml
:
Wecom
Response
<
any
>
;
xml
:
Wecom
EventResponse
;
};
if
(
!
parsedData
?.
Encrypt
)
{
logger
.
warn
(
'
Invalid xml: %s
'
,
rawData
);
...
...
@@ -103,7 +104,7 @@ export default class HttpServer extends Adapter<BotConfig, AdapterConfig> {
return
;
}
parsedData
.
body
=
this
.
xmlParser
.
parse
(
parsedData
.
data
.
message
)
.
xml
as
WecomEvent
Response
;
.
xml
as
WecomEvent
Body
;
if
(
!
parsedData
.
body
)
{
logger
.
warn
(
'
Invalid decrypted xml message: %s
'
,
...
...
src/index.ts
View file @
747d0148
// import 'source-map-support/register';
import
{
WecomEventResponse
}
from
'
./def
'
;
import
{
WecomEvent
Body
,
WecomEvent
Response
}
from
'
./def
'
;
import
{
Adapter
,
Session
}
from
'
koishi
'
;
import
HttpServer
from
'
./http
'
;
import
{
BotConfig
,
WeComBot
}
from
'
./bot
'
;
...
...
@@ -7,10 +7,11 @@ import { AdapterConfig } from './utils';
declare
module
'
koishi
'
{
interface
Session
{
wecom
?:
WecomEvent
Response
;
wecom
?:
WecomEvent
Body
;
}
interface
EventMap
{
'
wecom/event
'
(
session
:
Session
):
void
;
'
wecom/message
'
(
session
:
Session
):
void
;
}
}
...
...
src/utils.ts
View file @
747d0148
...
...
@@ -42,8 +42,9 @@ export function adaptSession(bot: WeComBot, input: WecomEventResponse) {
}
const
session
:
Partial
<
Session
>
=
{
selfId
:
bot
.
selfId
,
targetId
:
body
.
ToUserName
,
messageId
:
body
.
MsgId
?.
toString
(),
wecom
:
input
,
wecom
:
body
,
userId
:
body
.
FromUserName
,
channelId
:
body
.
FromUserName
,
timestamp
:
body
.
CreateTime
,
...
...
@@ -51,7 +52,7 @@ export function adaptSession(bot: WeComBot, input: WecomEventResponse) {
if
(
body
.
MsgType
===
'
event
'
)
{
session
.
type
=
'
wecom/event
'
;
session
.
subtype
=
body
.
Event
;
}
else
{
}
else
if
(
body
.
MsgType
===
'
text
'
||
body
.
MsgType
===
'
image
'
)
{
session
.
type
=
'
message
'
;
session
.
subtype
=
'
private
'
;
session
.
author
=
{
...
...
@@ -68,17 +69,18 @@ export function adaptSession(bot: WeComBot, input: WecomEventResponse) {
url
:
imageBody
.
PicUrl
,
});
break
;
default
:
return
;
}
}
else
{
session
.
type
=
'
wecom/message
'
;
session
.
subtype
=
body
.
MsgType
;
}
return
session
;
}
export
function
dispatchSession
(
bot
:
WeComBot
,
message
:
Wecom
Response
<
any
>
)
{
export
function
dispatchSession
(
bot
:
WeComBot
,
message
:
Wecom
EventResponse
)
{
const
payload
=
adaptSession
(
bot
,
message
);
if
(
!
payload
)
return
;
const
session
=
new
Session
(
bot
,
payload
);
session
.
wecom
=
message
;
session
.
wecom
=
message
.
body
;
bot
.
adapter
.
dispatch
(
session
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment