Skip to content

Commit d4f834b

Browse files
committed
message support to Url,miniProgram
1 parent 3e99e96 commit d4f834b

File tree

1 file changed

+35
-0
lines changed
  • wechaty/src/main/kotlin/io/github/wechaty/user

1 file changed

+35
-0
lines changed

wechaty/src/main/kotlin/io/github/wechaty/user/Message.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,44 @@ open class Message(wechaty: Wechaty,val id: String) : Sayable, Accessory(wechaty
292292
throw Exception("not a image type, type is "+ this.type())
293293
}
294294
return wechaty.imageMessager.create(this.id);
295+
}
296+
297+
fun toContact():Contact{
298+
299+
if(this.type() != MessageType.Contact){
300+
throw Exception("message not a ShareCard")
301+
}
302+
303+
val contactId = wechaty.getPuppet().messageContact(this.id).get()
304+
if(StringUtils.isEmpty(contactId)){
305+
throw Exception("can not get contact id by message ${this.id}")
306+
}
307+
308+
val contact = wechaty.contactManager.load(contactId)
309+
contact.ready()
310+
return contact
311+
}
295312

313+
fun toUrlLink():UrlLink{
314+
if(this.type() != MessageType.Url){
315+
throw Exception("message not a Url Link")
316+
}
317+
318+
val urlPayload = wechaty.getPuppet().messageUrl(this.id).get()
319+
return UrlLink(urlPayload)
320+
}
321+
322+
fun toMiniProgram():MiniProgram{
323+
324+
if(this.type() != MessageType.MiniProgram){
325+
throw Exception("message not a MiniProgram")
326+
}
327+
328+
val miniProgramPayload = wechaty.getPuppet().messageMiniProgram(this.id).get()
329+
return MiniProgram(miniProgramPayload)
296330
}
297331

332+
298333
fun toFileBox():FileBox{
299334
if(this.type() == MessageType.Text){
300335
throw Exception("text message no file")

0 commit comments

Comments
 (0)