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

Wechaty.send() error when send message to the room #89

Closed
lijiarui opened this Issue Nov 12, 2016 · 7 comments

Comments

Projects
None yet
2 participants
@lijiarui
Copy link
Member

lijiarui commented Nov 12, 2016

Run npm run doctor or wechaty run doctor(for docker user), paste output here

wechaty@0.5.9 doctor /wechaty
ts-node bin/doctor

Wechaty Doctor

  1. Wechaty version: 0.5.9
  2. Linux x64 version 3.16.0-4-amd64 memory 283/1000 MB
  3. Docker: true
  4. Node version: v7.1.0

Expected behavior

Using function 'Message.to()' to set the destination for the message, when the destination is Room, the function 'Wechaty.send(message) ' occured the following error:

ERR Wechaty send() exception: to.name is not a function
(node:34) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 6): TypeError: to.name is not a function

Code

import { Wechaty,Message,Room} from 'wechaty'

const bot = Wechaty.instance()
bot
.on('scan' ,(url,code)=>{console.log(url)})

.on('login',username=>{console.log(username.name())})

.on('message', m=> {
  const content = m.content()
  var testmsg = new Message()

  if(/^contact/.test(content)){
    console.log(`receive message${content}`)
    testmsg.to('lizhuohuan')
    testmsg.content('hellomessage')
    bot.send(testmsg)
  }

  if(/^filehelper/.test(content)){
    console.log(`receive message${content}`)
    testmsg.to('filehelper')
    testmsg.content('hellomessage')
    bot.send(testmsg)
  }

  if(/^roomname/.test(content)){
    console.log(`receive message${content}`)
    testmsg.to('testmsg')
    testmsg.content('hellomessage')
    bot.send(testmsg)
  }

  if(/^roomid/.test(content)){
    console.log(`receive message${content}`)
    testmsg.to('@@85c81ebaabbaf9ab18b2e4b358e032fc2add11d232a9a16c1bc0c07a19567f5a')
    testmsg.content('hellomessage')
    bot.send(testmsg)
  }
  
  if(/^room/.test(content)){
    Room.find({topic:'testmsg'})
     .then(roomfind=>{
      if(roomfind){
        console.log(`roomfind---${roomfind.topic()}`)
        testmsg.to(roomfind)
        testmsg.content('sendhello')
        console.log(testmsg.to())
        bot.send(testmsg)
      }
    })
  }
})
.init()

In order to find the reason, I tried 5 methods to test as the above code shows, and find something useful as follows:

1.send message to a contact(the parameter is "微信号")

log as follows:
SILL Contact constructor(MissJuzimi)
SILL PuppetWeb send() destination: , content: hellomessage)

Although log showed destination is null, but my contact 'MissJuzimi' can receive the message 'hellomessage'
No Error Report

2.send message to a filehelper

log as follows:
SILL PuppetWeb send() destination: File Transfer, content: hellomessage)

filehelper can receive the message 'hellomessage'
No Error Report

3.send message to a room called 'testmsg'(parameter is roomtopic)

log as follows:
SILL Contact constructor(testmsg)
SILL PuppetWeb send() destination: , content: hellomessage)

the log showed destination is null, Room 'testmsg' cannot receive the message 'hellomessage' .I thought maybe the code dealt 'testmsg' as '微信号', and it can't find 'testmsg' in my friend, so it failed to send the message.
No Error Report

4.send message to a room called 'testmsg'(parameter is roomid)

log as follows:
SILL Room constructor(@@85c81ebaabbaf9ab18b2e4b358e032fc2add11d232a9a16c1bc0c07a19567f5a)
ERR Wechaty send() exception: to.name is not a function
(node:34) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: to.name is not a function
(node:34) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

No PuppetWeb send(),Error Report.

5.send message to a room called 'testmsg'(parameter is Room)

log as follows:
ERR Wechaty send() exception: to.name is not a function
(node:34) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 6): TypeError: to.name is not a function

No PuppetWeb send(),Error Report.

Paste the full output logs here with WECHATY_LOG=silly set

As the code showd above, I used function 'wechaty.send()' in following scenario:

1.send message to a contact(the parameter is "微信号")

 if(/^contact/.test(content)){
    console.log(`receive message${content}`)
    testmsg.to('lizhuohuan')
    testmsg.content('hellomessage')
    bot.send(testmsg)
  }

SILL Message constructor() SN:62
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Message constructor() SN:63
receive messagecontact
SILL Contact constructor(MissJuzimi)
SILL PuppetWeb send() destination: , content: hellomessage)
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() open
SILL PuppetWebBrowser Browser.execute(" const callback = arguments[arguments.length - 1] const isAsync = (typeof ... ")
SILL StateMonitor Browser:target() open
SILL Message constructor() SN:64
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Contact get contact via PuppetWeb
SILL PuppetWebBridge getContact() retryPromise: attampt 1/35 time for timeout 306250
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() open
SILL PuppetWebBrowser Browser.execute(" const callback = arguments[arguments.length - 1] const isAsync = (typeof ... ")
SILL StateMonitor Browser:target() open
SILL Contact contactGetter(MissJuzimi) resolved
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Contact get contact via PuppetWeb
SILL PuppetWebBridge getContact() retryPromise: attampt 1/35 time for timeout 306250
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() open
SILL PuppetWebBrowser Browser.execute(" const callback = arguments[arguments.length - 1] const isAsync = (typeof ... ")
SILL StateMonitor Browser:target() open
SILL Contact contactGetter(MissJuzimi) resolved
SILL Message constructor() SN:65

2.send message to a filehelper

if(/^filehelper/.test(content)){
    console.log(`receive message${content}`)
    testmsg.to('filehelper')
    testmsg.content('hellomessage')
    bot.send(testmsg)
  }

SILL Message constructor() SN:14
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Message constructor() SN:15
receive messagefilehelper
SILL PuppetWeb send() destination: File Transfer, content: hellomessage)
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() open
SILL PuppetWebBrowser Browser.execute(" const callback = arguments[arguments.length - 1] const isAsync = (typeof ... ")
SILL StateMonitor Browser:target() open
SILL Message constructor() SN:16
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Message constructor() SN:17

3.send message to a room called 'testmsg'(parameter is roomtopic)

if(/^roomname$/.test(content)){
    console.log(`receive message${content}`)
    testmsg.to('testmsg')
    testmsg.content('hellomessage')
    bot.send(testmsg)
  }

SILL Message constructor() SN:3
receive messageroomname
SILL Contact constructor(testmsg)
SILL PuppetWeb send() destination: , content: hellomessage)
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() open
SILL PuppetWebBrowser Browser.execute(" const callback = arguments[arguments.length - 1] const isAsync = (typeof ... ")
SILL StateMonitor Browser:target() open
SILL Message constructor() SN:4
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Contact get contact via PuppetWeb
SILL PuppetWebBridge getContact() retryPromise: attampt 1/35 time for timeout 306250
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() open
SILL PuppetWebBrowser Browser.execute(" const callback = arguments[arguments.length - 1] const isAsync = (typeof ... ")
SILL StateMonitor Browser:target() open
SILL Contact contactGetter(testmsg) resolved
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Contact get contact via PuppetWeb
SILL PuppetWebBridge getContact() retryPromise: attampt 1/35 time for timeout 306250
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() open
SILL PuppetWebBrowser Browser.execute(" const callback = arguments[arguments.length - 1] const isAsync = (typeof ... ")
SILL StateMonitor Browser:target() open
SILL Contact contactGetter(testmsg) resolved
SILL Message constructor() SN:5

4.send message to a room called 'testmsg'(parameter is roomid)

if(/^roomid$/.test(content)){
   console.log(`receive message${content}`)
   testmsg.to('@@85c81ebaabbaf9ab18b2e4b358e032fc2add11d232a9a16c1bc0c07a19567f5a')
   testmsg.content('hellomessage')
   bot.send(testmsg)
 }

SILL Message constructor() SN:6
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Message constructor() SN:7
receive messageroomid
SILL Room constructor(@@85c81ebaabbaf9ab18b2e4b358e032fc2add11d232a9a16c1bc0c07a19567f5a)
ERR Wechaty send() exception: to.name is not a function
(node:34) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: to.name is not a function
(node:34) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

5.send message to a room called 'testmsg'(parameter is Room)

if(/^room$/.test(content)){
    Room.find({topic:'testmsg'})
     .then(roomfind=>{
      if(roomfind){
        console.log(`roomfind---${roomfind.topic()}`)
        testmsg.to(roomfind)
        testmsg.content('sendhello')
        console.log(testmsg.to())
        bot.send(testmsg)
      }
    })
  }

SILL Message constructor() SN:8
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Message constructor() SN:9
VERB Room find({ topic: testmsg })
VERB Room findAll({ topic: testmsg })
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() open
SILL PuppetWebBrowser Browser.execute(" const callback = arguments[arguments.length - 1] const isAsync = (typeof ... ")
SILL StateMonitor Browser:target() open
SILL Room constructor(@@8fea12bb9003ff485823d9f2fb91a9117e82289e6dfe17b0c0364853f61d806d)
SILL Room ready()
SILL PuppetWebBridge getContact() retryPromise: attampt 1/35 time for timeout 306250
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() open
SILL PuppetWebBrowser Browser.execute(" const callback = arguments[arguments.length - 1] const isAsync = (typeof ... ")
SILL StateMonitor Browser:target() open
SILL Room contactGetter(@@8fea12bb9003ff485823d9f2fb91a9117e82289e6dfe17b0c0364853f61d806d) resolved
SILL Contact constructor(@30caeda9cac31070014cbfac5a8f2ff89e653c7573e9116da7f57351ed4815ef)
SILL Contact constructor(@704a71ffdd97ec88cc54c72ff510a333e3f03632d5dee73331f4cc5ab38882c2)
VERB Contact remark()
VERB Contact remark()
VERB Contact remark()
SILL Contact ready(function)
SILL Contact ready(function)
SILL PuppetWebBridge getContact() retryPromise: attampt 1/35 time for timeout 306250
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() open
SILL Contact ready(function)
SILL PuppetWebBridge getContact() retryPromise: attampt 1/35 time for timeout 306250
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() open
SILL PuppetWebBrowser Browser.execute(" const callback = arguments[arguments.length - 1] const isAsync = (typeof ... ")
SILL StateMonitor Browser:target() open
SILL PuppetWebBrowser Browser.execute(" const callback = arguments[arguments.length - 1] const isAsync = (typeof ... ")
SILL StateMonitor Browser:target() open
SILL Contact contactGetter(@30caeda9cac31070014cbfac5a8f2ff89e653c7573e9116da7f57351ed4815ef) resolved
SILL Contact contactGetter(@704a71ffdd97ec88cc54c72ff510a333e3f03632d5dee73331f4cc5ab38882c2) resolved
roomfind---testmsg
Room {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
id: '@@8fea12bb9003ff485823d9f2fb91a9117e82289e6dfe17b0c0364853f61d806d',
rawObj:
{ Alias: '',
AppAccountFlag: 0,
AttrStatus: 0,
ChatRoomId: 0,
City: '',
ContactFlag: 0,
DisplayName: '',
EncryChatRoomId: '@04fbafa7ee5e60459976be35388159c2',
HeadImgUrl: '/cgi-bin/mmwebwx-bin/webwxgetheadimg?seq=0&username=@@8fea12bb9003ff485823d9f2fb91a9117e82289e6dfe17b0c0364853f61d806d&skey=',
HideInputBarFlag: 0,
KeyWord: '',
MMFromBatchGet: true,
MMFromBatchget: true,
MMInChatroom: true,
MMOrderSymbol: 'TESTMSG',
MemberCount: 3,
MemberList: [ [Object], [Object], [Object] ],
NickName: 'testmsg',
OwnerUin: 121141715,
PYInitial: 'TESTMSG',
PYQuanPin: 'testmsg',
Province: '',
RemarkName: '',
RemarkPYInitial: '',
RemarkPYQuanPin: '',
Sex: 0,
Signature: '',
SnsFlag: 0,
StarFriend: 0,
Statues: 1,
Uin: 0,
UniFriend: 0,
UserName: '@@8fea12bb9003ff485823d9f2fb91a9117e82289e6dfe17b0c0364853f61d806d',
VerifyFlag: 0,
stranger: true },
obj:
{ id: '@@8fea12bb9003ff485823d9f2fb91a9117e82289e6dfe17b0c0364853f61d806d',
encryId: '@04fbafa7ee5e60459976be35388159c2',
topic: 'testmsg',
ownerUin: 121141715,
memberList: [ [Object], [Object], [Object] ],
nickMap:
Map {
'@875673659a0a8d00fd964584ea07fdb7': '李佳芮',
'@30caeda9cac31070014cbfac5a8f2ff89e653c7573e9116da7f57351ed4815ef': '邀群助手',
'@704a71ffdd97ec88cc54c72ff510a333e3f03632d5dee73331f4cc5ab38882c2': 'wuli舞哩客服' } } }
ERR Wechaty send() exception: to.name is not a function
(node:34) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 6): TypeError: to.name is not a function

@huan

This comment has been minimized.

Copy link
Member

huan commented Nov 12, 2016

The code you posted in issue should be the minimized code snip that could be run by copy/paste. The shorter, the better.

This issue is related to #88 , and should be fixed by the related committed.

BTW: with the latest code, your code can not run message.to(room) anymore. you need to use message.room(room) instead.

Please have a try with the latest code and let me know if this issue is gone.

@lijiarui

This comment has been minimized.

Copy link
Member Author

lijiarui commented Nov 12, 2016

Sorry, this issue still exists.

wechaty version as follows:

Wechaty Doctor

  1. Wechaty version: 0.6.5
  2. Linux x64 version 3.16.0-4-amd64 memory 325/1000 MB
  3. Docker: true
  4. Node version: v7.1.0

code as follows:

import { Wechaty,Message,Room} from 'wechaty'

const bot = Wechaty.instance()
bot
.on('scan' ,(url,code)=>{console.log(url)})

.on('login',username=>{console.log(username.name())})

.on('message', m=> {
  const content = m.content()
  var testmsg = new Message()
  if(/^room$/.test(content)){
    Room.find({topic:'testmsg'})
     .then(roomfind=>{
      if(roomfind){
        testmsg.room(roomfind)
        testmsg.content('sendhello')
        bot.send(testmsg)
      }
    })
  }
})
.init()

error log as follows:

ERR Wechaty send() exception: id not found
(node:21) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): Error: id not found
(node:21) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

ERR Wechaty send() exception:to.name is not a function changed to ERR Wechaty send() exception: id not found

@huan

This comment has been minimized.

Copy link
Member

huan commented Nov 12, 2016

it seems you are not using the latest code: there's no to.name inside the new code anymore. please run git pull

Additional two question for you:

  1. why your version in npm run doctor output is not a git hashtag? are you running code in a git cloned repository directory? (this is my output: 1. Wechaty version: #git[d8854ed log for https://travis-ci.org/wechaty/wechaty/jobs/175324931#L1385])
  2. why do you use bot.send()? it is a low-level API and you should avoid use it if possible. in your case, it seems roomfind.say() is a better way to do the same thing?
@lijiarui

This comment has been minimized.

Copy link
Member Author

lijiarui commented Nov 12, 2016

sorry, I change another environment without docker, and git pull, but I cannot run any code.

when I run npm run doctor, it occurs the following error.

root@orangiss:~/wechaty# npm run doctor

wechaty@0.6.5 doctor /root/wechaty
ts-node bin/doctor

Error: Cannot find module 'is-docker'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/root/wechaty/src/config.ts:7:19)
at Module._compile (module.js:570:32)
at Module.m._compile (/root/wechaty/node_modules/ts-node/src/index.ts:403:23)
at Module._extensions..js (module.js:579:10)
at Object.require.extensions.(anonymous function) as .ts
at Module.load (module.js:487:32)

npm ERR! Linux 3.16.0-4-amd64
npm ERR! argv "/root/.nvm/v6.9.1/bin/node" "/root/.nvm/v6.9.1/bin/npm" "run" "doctor"
npm ERR! node v6.9.1
npm ERR! npm v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! wechaty@0.6.5 doctor: ts-node bin/doctor
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the wechaty@0.6.5 doctor script 'ts-node bin/doctor'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the wechaty package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ts-node bin/doctor
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs wechaty
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls wechaty
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /root/wechaty/npm-debug.log

I didn't use docker in this environment, could you help me ?

@lijiarui

This comment has been minimized.

Copy link
Member Author

lijiarui commented Nov 12, 2016

Additional two supplements:

1.this environment can run wechaty successful before I pull the latest code.

2.I meant there is no 'to.name' error, there is a new error 'id not found'

@huan

This comment has been minimized.

Copy link
Member

huan commented Nov 12, 2016

So you are not using the latest code. The latest code should not have this issue.

You are not using docker in this case. However, the program needs to know whether you are using docker, so the module is-docker is required.

You need to read your error log carefully. Here's not a support forum.

@lijiarui

This comment has been minimized.

Copy link
Member Author

lijiarui commented Nov 13, 2016

Thanks! Issus is fixed.

About your question:"why do you use bot.send()? it is a low-level API and you should avoid use it if possible. in your case, it seems roomfind.say() is a better way to do the same thing?"

I'm just trying the function message.to() and wechaty.send() as you gave in wiki, then use bot.send. I will avoid use it and use roomfind.say() instead of in the future. Thanks for your advice.

@lijiarui lijiarui closed this Nov 13, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment