1 Star 0 Fork 0

Wechaty / rust-wechaty-getting-started

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

rust-wechaty-getting-started

Gitpod Ready-to-Code Wechaty in Rust

Rust Wechaty Starter Project Template that Works Out-of-the-Box

Connecting Chatbots

Powered by Wechaty

Wechaty is a RPA SDK for Wechat Individual Account that can help you create a chatbot quickly.

A Basic Implementation of a Rust ChatBot

#![feature(async_closure)]

use wechaty::prelude::*;
use wechaty_puppet_service::PuppetService;

#[actix_rt::main]
async fn main() {
    let mut bot = Wechaty::new(
        PuppetService::new(PuppetOptions {
            endpoint: None,
            timeout: None,
            token: Some(env!("WECHATY_PUPPET_SERVICE_TOKEN").to_owned()),
        })
            .await
            .unwrap(),
    );
    bot.on_scan(async move |payload: ScanPayload, _ctx| {
            if let Some(qrcode) = payload.qrcode {
                println!("Visit https://wechaty.js.org/qrcode/{} to log in", qrcode)
            }
        })
        .on_login(async move |payload: LoginPayload<PuppetService>, _ctx| {
            println!("User {} logged in", payload.contact)
        })
        .on_message(async move |payload: MessagePayload<PuppetService>, _ctx| {
            println!("Message: {}", payload.message)
        })
        .start()
        .await;
}

Note: the example above requires nightly version of Rust since it makes use of the async_closure feature which is unstable now.

Requirements

  1. Cargo

The easiest way to get Cargo is to install the current stable release of [Rust] by using rustup. Installing Rust using rustup will also install cargo.

On Linux and macOS systems, this is done as follows:

curl https://sh.rustup.rs -sSf | sh

It will download a script, and start the installation. If everything goes well, you’ll see this appear:

Rust is installed now. Great!

On Windows, download and run [rustup-init.exe]. It will start the installation in a console and present the above message on success.

After this, you can use the rustup command to also install beta or nightly channels for Rust and Cargo.

The contents above are quoted from The Cargo Book.

Install

make install

Run

Get a Token for your Bot first. Learn more from our Wechaty Developers Program

export WECHATY_PUPPET_SERVICE_TOKEN=your_token_at_here

make bot

Wechaty Getting Started in Multiple Languages

Badge

Wechaty in Rust

[![Wechaty in Rust](https://img.shields.io/badge/Wechaty-Rust-7de)](https://github.com/wechaty/rust-wechaty)

Maintainers

@wechaty/rust

Copyright & License

  • Code & Docs © 2021 - now Wechaty Contributors https://github.com/wechaty
  • Code released under the Apache-2.0 License
  • Docs released under Creative Commons

空文件

简介

Rust Wechaty Starter Project Template that Works Out-of-the-Box 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/wechaty/rust-wechaty-getting-started.git
git@gitee.com:wechaty/rust-wechaty-getting-started.git
wechaty
rust-wechaty-getting-started
rust-wechaty-getting-started
main

搜索帮助