Closed ccgulan closed 6 months ago
message.toLocation()
用这个方法获取位置信息的详情
@su-chang 没有在api参考说明里头找到这个方法,请问返回的是什么类型的数据,如何获取经纬度信息?
@su-chang 调用toLocation()报错如下: Error: LocationImpl: Wechaty User Class (WUC) can not be instantiated directly! See: https://github.com/wechaty/wechaty/issues/1217 at throwWechatifyError (file:///E:/wechat-robot-worpro_2/node_modules/wechaty/dist/esm/src/user-mixins/wechatify.js:18:11) at new AbstractWechatifyMixin (file:///E:/wechat-robot-worpro_2/node_modules/wechaty/dist/esm/src/user-mixins/wechatify.js:32:17) at new LocationMixin (file:///E:/wechat-robot-worpro_2/node_modules/wechaty/dist/esm/src/user-modules/location.js:27:9) at new ValidationUserClass (file:///E:/wechat-robot-worpro_2/node_modules/wechaty/dist/esm/src/user-mixins/validation.js:18:5) at new LocationImpl (file:///E:/wechat-robot-worpro_2/node_modules/wechaty/dist/esm/src/user-modules/location.js:52:1) at WechatifiedUserClass.toLocation (file:///E:/wechat-robot-worpro_2/node_modules/wechaty/dist/esm/src/user-modules/message.js:882:16) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async WechatyImpl.onMessage (file:///E:/wechat-robot-worpro_2/on-message.js:1083:13)
代码如下: export async function onMessage(msg) { if (!bot) { bot = this; } try { const room = msg.room() const from = msg.talker() var text = msg.text() / var local try{ local=await msg.toLocation() console.log(local); } catch (e) { console.error(e) }/
请提供wechaty相关依赖包的版本。
建议使用@juzi/wechaty@latest
@su-chang 版本如下,应该最新版本了,还是同样的问题 @juzi/wechaty@1.0.95
bot@1.18.7 E:\wechat-robot-worpro_2 ├── @chatie/eslint-config@1.2.2 ├── @chatie/git-scripts@0.6.2 ├── @chatie/tsconfig@4.9.1 ├── @juzi/wechaty@1.0.95 ├── @typescript-eslint/eslint-plugin@5.51.0 ├── axios@1.2.2 ├── chatgpt@5.0.7 ├── check-node-version@4.2.1 ├── dotenv@16.0.3 ├── eslint-config-standard-with-typescript@34.0.0 ├── eslint-config-standard@17.0.0 ├── eslint-plugin-import@2.27.5 ├── eslint-plugin-n@15.6.1 ├── eslint-plugin-promise@6.1.1 ├── eslint@8.33.0 ├── is-pr@2.0.0 ├── node-cron@3.0.3 extraneous ├── openai@3.1.0 ├── qrcode-terminal@0.12.0 ├── ts-node@10.9.1 ├── typescript@4.9.5 ├── undici@5.20.0 ├── wechaty-cqrs@0.7.5 ├── wechaty-puppet-mock@1.18.2 ├── wechaty-puppet-padlocal@1.20.1 ├── wechaty@1.20.2 └── xml2js@0.4.23
@ccgulan 获取定位消息的时候先进行类型判断
if (message.type() === PUPPET.types.Message.Location) {
local=await msg.toLocation()
}
@ccgulan 获取定位消息的时候先进行类型判断
if (message.type() === PUPPET.types.Message.Location) { local=await msg.toLocation() }
@su-chang 你好,加入以上代码后,出现如下错误 ReferenceError: PUPPET is not defined at WechatyImpl.onMessage (file:///E:/wechat-robot-worpro_2/on-message.js:1085:26) at WechatyImpl.emit (node:events:513:28) at WechatyImpl.emit (file:///E:/wechat-robot-worpro_2/node_modules/wechaty/dist/esm/src/wechaty-mixins/gerror-mixin.js:31:30) at PuppetService.
(file:///E:/wechat-robot-worpro_2/node_modules/wechaty/dist/esm/src/wechaty-mixins/puppet-mixin.js:219:38)
你能正常启动代码收发消息么? 最好提供下你出这个报错的完整代码。看起来像是初始化有问题。
你能正常启动代码收发消息么? 最好提供下你出这个报错的完整代码。看起来像是初始化有问题。
@su-chang 能正常收发消息,代码如下: if (!bot) { bot = this; } try { const room = msg.room() const from = msg.talker() var text = msg.text()
var local
try{
console.log(msg.type())
if (msg.type() === PUPPET.types.Message.Location) {
local=await msg.toLocation()
console.log(local);
}
} catch (e) {
console.error(e)
}
bot初始化和启动的代码也提供下。
bot初始化和启动的代码也提供下。
@su-chang 初始化的终端信息: $ npm run start
bot@1.18.7 start node bot.js
16:27:23 WARN GrpcManager initClient() TLS: disabled (INSECURE)
16:27:23 INFO StarterBot Contact<效能管家> login
16:27:23 INFO StarterBot Starter Bot Started.
位置信息
7
ReferenceError: PUPPET is not defined
at WechatyImpl.onMessage (file:///E:/wechat-robot-worpro_2/on-message.js:1085:25)
at WechatyImpl.emit (node:events:513:28)
at WechatyImpl.emit (file:///E:/wechat-robot-worpro_2/node_modules/wechaty/dist/esm/src/wechaty-mixins/gerror-mixin.js:31:30)
at PuppetService.
代码如下:
const puppet = new PuppetServer({
token: ${config.padlocal_key}
})
const bot = WechatyBuilder.build({
name: 'bot',
puppet: 'wechaty-puppet-service',
puppetOptions: {
tls: {
disable: true
},
timeoutSeconds: 4 * 60,
token: ${config.padlocal_key}
}
})
bot.on('scan', onScan) bot.on('login', onLogin) bot.on('logout', onLogout) bot.on('message', onMessage) bot.on('room-invite', roomInvitation) bot.on('room-join', onRoomJoin) bot.on('friendship', onFriendship) bot.on('error', onError)
try { bot.start() .then(() => log.info('StarterBot', 'Starter Bot Started.')) .catch(e => log.error('StarterBot', e)) } catch (error) { console.log('init error: ', error); } //异常捕获 process.on('unhandledRejection', (reason, p) => { console.log('Unhandled Rejection at:', p, 'reason:', reason); });
哥们,这个报错很明显是说没找到PUPPET的引用。你要先从wechaty中引入PUPPET.types。(根据你具体使用的方法不同,路径可能有区别。)
哥们,这个报错很明显是说没找到PUPPET的引用。你要先从wechaty中引入PUPPET.types。(根据你具体使用的方法不同,路径可能有区别。) @hcfw007 不好意思,我比较菜,你们网上的api参考也比较简单,能否给一份详细的api说明
无后续反馈,问题关闭。
普通微信发送位置信息可以获取如下信息
但是企业微信获取不到