Coder Social home page Coder Social logo

wechaty-mqtt-link's Introduction

简介

wechaty-mqtt-link是一个基于wechaty+mqtt的聊天机器人客户端,可以使用mqtt与云端保持连接,向部署在异构环境的业务应用同步聊天消息及接受远程控制。

搭配 easy-chatbot-controller 使用轻松实现无服务架构http请求控制机器人

wechaty版本依赖:

wechaty-puppet-padlocal < v1.0 (参考package.json)

wechaty-puppet-wxwork v0.62.1 (参考package-padlocal.json)

实现架构

在本地或云服务器运行wechaty client -> 使用百度云物联网核心套件中MQTT+规则引擎实现微信消息转发Webhook

image

如何从百度云IoTCore中获得MQTT用户名和密码

示例

import { Wechaty, ScanStatus, log } from 'wechaty'

import qrcodeTerminal from 'qrcode-terminal'

import { ChatDevice } from 'wechaty-mqtt-link'

const bot = new Wechaty()
const chatdev = new ChatDevice(process.env['MQTT_USERNAME'], process.env['MQTT_PASSWORD'], process.env['BOTID'])

async function onMessage(msg) {
    log.info('StarterBot', msg.toString())
    // console.debug(msg)
    chatdev.pub_message(msg)
    if (msg.text() == 'ding') {
        msg.say('dong')
    }
}

bot
    .on('login', (user) => {
        console.log(`User ${user} logined`)
        chatdev.init(bot)
    })
    .on('message', onMessage)
    .start()
    .catch((e) => console.error(e))

功能支持

接收消息

  • 文本
  • 图片
  • 文件
  • 视频
  • 动图
  • 联系人
  • 小程序卡片

发布消息

  • 单发消息
  • 群内@某人
  • 创建群
  • 请求全部联系人列表
  • 请求全部群列表

wechaty-mqtt-link's People

Contributors

leochen-g avatar atorber avatar choogoo avatar

Stargazers

HeisenBerg? avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.