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
a30967cc
Commit
a30967cc
authored
Mar 18, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add full type support
parent
eb84676d
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
252 additions
and
54 deletions
+252
-54
dev/index.ts
dev/index.ts
+4
-6
src/def/def.ts
src/def/def.ts
+0
-26
src/def/events.ts
src/def/events.ts
+56
-0
src/def/index.ts
src/def/index.ts
+5
-2
src/def/specific/ApprovalInfo.ts
src/def/specific/ApprovalInfo.ts
+48
-0
src/def/specific/ChangeContact.ts
src/def/specific/ChangeContact.ts
+35
-0
src/def/specific/ChangeContactUser.ts
src/def/specific/ChangeContactUser.ts
+39
-0
src/def/specific/WeComAgentInfo.ts
src/def/specific/WeComAgentInfo.ts
+0
-0
src/def/specific/WeComUser.ts
src/def/specific/WeComUser.ts
+0
-0
src/index.ts
src/index.ts
+58
-4
src/utils.ts
src/utils.ts
+7
-16
No files found.
dev/index.ts
View file @
a30967cc
...
...
@@ -26,12 +26,10 @@ app.plugin(adapterPlugin, {
encodingAESKey
:
'
encodingAESKey
'
,
// 加密密钥,在应用消息接收设置中设置并填入
});
app
.
on
(
'
wecom/event
'
,
(
session
)
=>
{
console
.
log
(
`Got event
${
JSON
.
stringify
(
session
.
wecom
)}
`
);
});
app
.
on
(
'
wecom/message
'
,
(
session
)
=>
{
console
.
log
(
`Got custom message
${
JSON
.
stringify
(
session
.
wecom
)}
`
);
app
.
on
(
'
wecom/LOCATION
'
,
(
session
)
=>
{
console
.
log
(
`Got location for
${
session
.
userId
}
:
${
session
.
wecom
.
Longitude
}
${
session
.
wecom
.
Latitude
}
`
,
);
});
app
.
on
(
'
message
'
,
(
session
)
=>
{
...
...
src/def/def.ts
View file @
a30967cc
...
...
@@ -37,7 +37,6 @@ export interface WecomEventBody {
Event
?:
string
;
AgentID
:
number
;
MsgId
?:
number
;
EventKey
?:
string
;
}
export
interface
WecomChatBody
extends
WecomEventBody
{
...
...
@@ -74,31 +73,6 @@ export interface WecomLinkBody extends WecomEventBody {
PicUrl
:
string
;
}
export
interface
CardEventSelectedItems
{
SelectedItem
:
CardEventSelectedItem
|
CardEventSelectedItem
[];
}
export
interface
CardEventSelectedItem
{
QuestionKey
:
string
;
OptionIds
:
CardEventOptionIds
;
}
export
interface
CardEventOptionIds
{
OptionId
:
string
|
string
[];
}
export
interface
WecomCardEventBody
extends
WecomEventBody
{
TaskId
:
string
;
CardType
:
string
;
SelectedItems
?:
CardEventSelectedItems
;
}
export
interface
WecomLocationBody
extends
WecomEventBody
{
Latitude
:
number
;
Longitude
:
number
;
Precision
:
number
;
}
export
interface
TokenReturnMessage
extends
WecomApiResponse
{
access_token
:
string
;
expires_in
:
number
;
...
...
src/def/events.ts
0 → 100644
View file @
a30967cc
import
{
WecomEventBody
}
from
'
./def
'
;
import
{
Session
}
from
'
koishi
'
;
type
MayBeArray
<
T
>
=
T
|
T
[];
export
interface
EventKeyBody
{
EventKey
:
string
;
}
export
interface
ScanCodeEventBody
extends
EventKeyBody
{
ScanCodeInfo
:
{
ScanType
:
string
;
ScanResult
:
string
;
};
}
export
interface
PhotoEventBody
extends
EventKeyBody
{
SendPicsInfo
:
{
Count
:
number
;
PicsList
:
{
item
:
MayBeArray
<
{
PicMd5Sum
:
string
;
}
>
;
};
};
}
export
interface
CardEventSelectedItems
{
SelectedItem
:
CardEventSelectedItem
|
CardEventSelectedItem
[];
}
export
interface
CardEventSelectedItem
{
QuestionKey
:
string
;
OptionIds
:
CardEventOptionIds
;
}
export
interface
CardEventOptionIds
{
OptionId
:
string
|
string
[];
}
export
interface
WecomCardEventBody
{
TaskId
:
string
;
CardType
:
string
;
SelectedItems
?:
CardEventSelectedItems
;
}
export
interface
CardEvent
extends
EventKeyBody
{
TaskId
:
string
;
CardType
:
string
;
ResponseCode
:
number
;
}
// eslint-disable-next-line @typescript-eslint/ban-types
export
type
WecomEventFunction
<
T
=
{}
>
=
(
session
:
Session
&
{
wecom
:
WecomEventBody
&
T
},
)
=>
void
;
src/def/index.ts
View file @
a30967cc
export
*
from
'
./def
'
;
export
*
from
'
./WeComUser
'
;
export
*
from
'
./WeComAgentInfo
'
;
export
*
from
'
./specific/WeComUser
'
;
export
*
from
'
./specific/WeComAgentInfo
'
;
export
*
from
'
./specific/ApprovalInfo
'
;
export
*
from
'
./specific/ChangeContact
'
;
export
*
from
'
./events
'
;
src/def/specific/ApprovalInfo.ts
0 → 100644
View file @
a30967cc
export
interface
ApprovalInfo
{
ThirdNo
:
string
;
OpenSpName
:
string
;
OpenTemplateId
:
string
;
OpenSpStatus
:
string
;
ApplyTime
:
string
;
ApplyUserName
:
string
;
ApplyUserId
:
string
;
ApplyUserParty
:
string
;
ApplyUserImage
:
string
;
ApprovalNodes
:
ApprovalNodes
;
NotifyNodes
:
NotifyNodes
;
approverstep
:
string
;
}
interface
NotifyNodes
{
NotifyNode
:
NotifyNode
|
NotifyNode
[];
}
interface
NotifyNode
{
ItemName
:
string
;
ItemUserId
:
string
;
ItemImage
:
string
;
}
interface
ApprovalNodes
{
ApprovalNode
:
ApprovalNode
|
ApprovalNode
[];
}
interface
ApprovalNode
{
NodeStatus
:
string
;
NodeAttr
:
string
;
NodeType
:
string
;
Items
:
Items
;
}
interface
Items
{
Item
:
Item
|
Item
[];
}
interface
Item
{
ItemName
:
string
;
ItemUserId
:
string
;
ItemImage
:
string
;
ItemStatus
:
string
;
ItemSpeech
:
string
;
ItemOpTime
:
string
;
}
src/def/specific/ChangeContact.ts
0 → 100644
View file @
a30967cc
import
{
ChangeContactUser
}
from
'
./ChangeContactUser
'
;
export
*
from
'
./ChangeContactUser
'
;
export
type
ChangeContact
<
K
extends
keyof
ChangeContactMap
=
keyof
ChangeContactMap
,
>
=
{
ChangeType
:
K
;
}
&
ChangeContactMap
[
K
];
export
interface
ChangeContactParty
{
Id
:
number
;
Name
:
string
;
ParentId
:
number
;
}
export
interface
ChangeContactMap
{
create_user
:
ChangeContactUser
;
update_user
:
ChangeContactUser
;
delete_user
:
{
UserID
:
string
;
};
create_party
:
ChangeContactParty
&
{
Order
:
number
};
update_party
:
ChangeContactParty
;
delete_party
:
{
Id
:
number
;
};
update_tag
:
{
TagId
:
number
;
AddUserItems
:
string
;
DelUserItems
:
string
;
AddPartyItems
:
string
;
DelPartyItems
:
string
;
};
}
src/def/specific/ChangeContactUser.ts
0 → 100644
View file @
a30967cc
export
interface
ChangeContactUser
{
UserID
:
string
;
Name
:
string
;
Department
:
string
;
MainDepartment
:
string
;
IsLeaderInDept
:
string
;
DirectLeader
:
string
;
Position
:
string
;
Mobile
:
string
;
Gender
:
string
;
Email
:
string
;
BizMail
:
string
;
Status
:
string
;
Avatar
:
string
;
Alias
:
string
;
Telephone
:
string
;
Address
:
string
;
ExtAttr
:
ExtAttr
;
}
interface
ExtAttr
{
Item
:
Item
[];
}
interface
Item
{
Name
:
string
;
Type
:
string
;
Text
?:
Text
;
Web
?:
Web
;
}
interface
Web
{
Title
:
string
;
Url
:
string
;
}
interface
Text
{
Value
:
string
;
}
src/def/WeComAgentInfo.ts
→
src/def/
specific/
WeComAgentInfo.ts
View file @
a30967cc
File moved
src/def/WeComUser.ts
→
src/def/
specific/
WeComUser.ts
View file @
a30967cc
File moved
src/index.ts
View file @
a30967cc
// import 'source-map-support/register';
import
{
WecomEventBody
,
WecomEventResponse
}
from
'
./def
'
;
import
{
Adapter
,
Session
}
from
'
koishi
'
;
import
{
ApprovalInfo
,
CardEvent
,
CardEventSelectedItems
,
ChangeContact
,
EventKeyBody
,
PhotoEventBody
,
ScanCodeEventBody
,
WecomEventBody
,
WecomEventFunction
,
}
from
'
./def
'
;
import
{
Adapter
}
from
'
koishi
'
;
import
HttpServer
from
'
./http
'
;
import
{
BotConfig
,
WeComBot
}
from
'
./bot
'
;
import
{
AdapterConfig
}
from
'
./utils
'
;
...
...
@@ -10,8 +20,52 @@ declare module 'koishi' {
wecom
?:
WecomEventBody
;
}
interface
EventMap
{
'
wecom/event
'
(
session
:
Session
):
void
;
'
wecom/message
'
(
session
:
Session
):
void
;
'
wecom/enter_agent
'
:
WecomEventFunction
;
'
wecom/subscribe
'
:
WecomEventFunction
;
'
wecom/unsubscribe
'
:
WecomEventFunction
;
'
wecom/LOCATION
'
:
WecomEventFunction
<
{
Latitude
:
number
;
Longitude
:
number
;
Precision
:
number
;
}
>
;
'
wecom/batch_job_result
'
:
WecomEventFunction
<
{
BatchJob
:
{
JobId
:
string
;
JobType
:
string
;
ErrCode
:
number
;
ErrMsg
:
string
;
};
}
>
;
'
wecom/click
'
:
WecomEventFunction
<
EventKeyBody
>
;
'
wecom/view
'
:
WecomEventFunction
<
EventKeyBody
>
;
'
wecom/scan
'
:
WecomEventFunction
<
ScanCodeEventBody
>
;
'
wecom/scancode_waitmsg
'
:
WecomEventFunction
<
ScanCodeEventBody
>
;
'
wecom/pic_sysphoto
'
:
WecomEventFunction
<
PhotoEventBody
>
;
'
wecom/pic_photo_or_album
'
:
WecomEventFunction
<
PhotoEventBody
>
;
'
wecom/pic_weixin
'
:
WecomEventFunction
<
PhotoEventBody
>
;
'
wecom/location_select
'
:
WecomEventFunction
<
EventKeyBody
&
{
SendLocationInfo
:
{
Location_X
:
number
;
Location_Y
:
number
;
Scale
:
number
;
Label
:
string
;
Poiname
:
string
;
};
}
>
;
'
wecom/share_agent_change
'
:
WecomEventFunction
;
'
wecom/share_chain_change
'
:
WecomEventFunction
;
'
wecom/template_card_event
'
:
WecomEventFunction
<
CardEvent
&
{
SelectedItems
:
CardEventSelectedItems
;
}
>
;
'
wecom/template_card_menu_event
'
:
WecomEventFunction
<
CardEvent
>
;
'
wecom/open_approval_change
'
:
WecomEventFunction
<
{
ApprovalInfo
:
ApprovalInfo
;
}
>
;
'
wecom/change_contact
'
:
WecomEventFunction
<
ChangeContact
>
;
}
}
...
...
src/utils.ts
View file @
a30967cc
...
...
@@ -4,10 +4,8 @@ import {
WecomChatBody
,
WecomEventResponse
,
WecomLinkBody
,
WecomLocationBody
,
WecomLocationMessageBody
,
WecomPicBody
,
WecomResponse
,
WeComUser
,
WecomVideoBody
,
WecomVoiceBody
,
...
...
@@ -55,10 +53,8 @@ export function adaptSession(bot: WeComBot, input: WecomEventResponse) {
timestamp
:
body
.
CreateTime
,
};
if
(
body
.
MsgType
===
'
event
'
)
{
session
.
type
=
'
wecom/event
'
;
session
.
subtype
=
body
.
Event
;
session
.
type
=
`wecom/
${
body
.
Event
}
`
;
}
else
{
let
isKnownMessage
=
true
;
switch
(
body
.
MsgType
)
{
case
'
text
'
:
const
textBody
=
body
as
WecomChatBody
;
...
...
@@ -98,18 +94,13 @@ export function adaptSession(bot: WeComBot, input: WecomEventResponse) {
});
break
;
default
:
isKnownMessage
=
false
;
return
;
}
if
(
isKnownMessage
)
{
session
.
type
=
'
message
'
;
session
.
subtype
=
'
private
'
;
session
.
author
=
{
userId
:
session
.
userId
,
};
}
else
{
session
.
type
=
'
wecom/message
'
;
session
.
subtype
=
body
.
MsgType
;
}
}
return
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