提交 03576233 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

#41 add say to Message

上级 c742cbba
......@@ -69,6 +69,10 @@ class Message {
protected obj = <MessageObj>{}
readyStream(): Promise<NodeJS.ReadableStream> {
throw Error('abstract method')
}
constructor(private rawObj?: MessageRawObj) {
Message.counter++
......@@ -247,6 +251,33 @@ class Message {
Message.TYPE[v] = k // Message.Type[1] = 'TEXT'
})
}
public say(content: string, replyTo?: Contact|Contact[]): Promise<any> {
log.verbose('Message', 'say(%s, %s)', content, replyTo)
const m = new Message()
m.room(this.room())
if (!replyTo) {
m.to(this.from())
m.content(content)
} else if (this.room()) {
let mentionList
if (Array.isArray(replyTo)) {
m.to(replyTo[0])
mentionList = replyTo.map(c => '@' + c.name()).join(' ')
} else {
m.to(replyTo)
mentionList = '@' + replyTo.name()
}
m.content(mentionList + ' ' + content)
}
return Wechaty.instance()
.send(m)
}
}
Message.initType()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册