Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Wechaty,
Message,
} from 'wechaty'
// log.level = 'verbose'
// log.level = 'silly'
/**
*
* `7217d7bce18c4bcfbe04ba7bdfaf9c08` for Wechaty demo
*
*/
const APIAI_API_KEY = '7217d7bce18c4bcfbe04ba7bdfaf9c08'
const brainApiAi = ApiAi(APIAI_API_KEY)
const bot = Wechaty.instance({ profile: config.default.DEFAULT_PROFILE })
console.log(`
Welcome to api.AI Wechaty Bot.
Api.AI Doc: https://docs.api.ai/v16/docs/get-started
Notice: This bot will only active in the room which name contains 'wechaty'.
/* if (m.room() && /Wechaty/i.test(m.room().name())) { */
Loading... please wait for QrCode Image Url and then scan to login.
`)
bot
.on('scan', (qrcode, status) => {
QrcodeTerminal.generate(qrcode)
console.log(`${qrcode}\n[${status}] Scan QR Code in above url to login: `)
})
/* tslint:disable:variable-name */
const qrcodeTerminal = require('qrcode-terminal')
/**
* Change `import { ... } from '../'`
* to `import { ... } from 'wechaty'`
* when you are runing with Docker or NPM instead of Git Source.
*/
import {
config,
Message,
Wechaty,
} from 'wechaty'
const bot = Wechaty.instance({ profile: config.default.DEFAULT_PROFILE })
bot
.on('scan', (qrcode, status) => {
qrcodeTerminal.generate(qrcode)
console.log(`${qrcode}\n[${status}] Scan QR Code in above url to login: `)
})
.on('login' , user => console.log(`${user} logined`))
.on('message', async function(msg) {
console.log(`RECV: ${msg}`)
if (msg.type() !== Message.Type.Audio) {
return // skip no-VOICE message
}
// const mp3Stream = await msg.readyStream()
3. Recongenize Verify Message
If you send friend request to me,
with a verify message 'ding',
I will accept your request automaticaly!
__________________________________________________
Hope you like it, and you are very welcome to
upgrade me for more super powers!
Please wait... I'm trying to login in...
`
console.log(welcome)
const bot = Wechaty.instance({ profile: config.default.DEFAULT_PROFILE })
bot
.on('login' , user => log.info('Bot', `${user.name()} logined`))
.on('logout' , user => log.info('Bot', `${user.name()} logouted`))
.on('error' , e => log.info('Bot', 'error: %s', e))
.on('scan', (qrcode, status) => {
qrTerm.generate(qrcode)
console.log(`${qrcode}\n[${status}] Scan QR Code in above url to login: `)
})
/**
*
* Wechaty Event: `friend`
*
*/
.on('friendship', async friendship => {
let logMsg
4. Change room topic
5. Monitor room events
6. etc...
If you send a message of magic word 'ding',
you will get a invitation to join my own room!
__________________________________________________
Hope you like it, and you are very welcome to
upgrade me for more super powers!
Please wait... I'm trying to login in...
`
console.log(welcome)
const bot = Wechaty.instance({ profile: config.default.DEFAULT_PROFILE })
bot
.on('scan', (qrcode, status) => {
qrTerm.generate(qrcode, { small: true })
console.log(`${qrcode}\n[${status}] Scan QR Code in above url to login: `)
})
.on('logout' , user => log.info('Bot', `"${user.name()}" logouted`))
.on('error' , e => log.info('Bot', 'error: %s', e))
/**
* Global Event: login
*
* do initialization inside this event.
* (better to set a timeout, for browser need time to download other data)
*/
.on('login', async function(user) {
} = require('wechaty')
const { onMessage } = require('./on-message')
const { onFriendship } = require('./on-friend')
const { onRoomJoin } = require('./on-room-join')
const welcome = `
=============== Powered by Wechaty ===============
-------- https://github.com/Chatie/wechaty --------
Please wait... I'm trying to login in...
`
console.info(welcome)
const bot = Wechaty.instance({ profile: config.default.DEFAULT_PROFILE })
bot
.on('scan', (qrcode, status) => {
require('qrcode-terminal').generate(qrcode)
console.info(`${qrcode}\n[${status}] Scan QR Code in above url to login: `)
})
.on('login', async function (user) {
log.info('Bot', `${user.name()} logined`)
await this.say(`wechaty logined`)
})
.on('logout', user => log.info('Bot', `${user.name()} logouted`))
.on('error', error => log.info('Bot', 'error: %s', error))
.on('message', onMessage)