GithubHelp home page GithubHelp logo

deno_wechat_robot's Introduction

deno_wechat_robot

企业微信自定义机器人。

使用

deno run --allow-net --allow-env https://raw.githubusercontent.com/justjavac/deno_wechat_robot/main/mod.ts helloworld

或者短域名版:

deno run --allow-net --allow-env https://git.io/JWVqI helloworld

如果你访问 github 不流畅,可以使用 jsdelivr 的 CDN 加速服务:

deno run --allow-net --allow-env https://cdn.jsdelivr.net/ghjustjavac/deno_wechat_robot/mod.ts helloworld

如果后面没有参数,则进入交互模式:

$ deno run --allow-net --allow-env https://git.io/JWVqI
请输入你想要发送的内容,按回车键结束:
hello<回车>
send success 👌

核心代码

const access_token = Deno.env.get("ACCESS_TOKEN");

const url = new URL("https://qyapi.weixin.qq.com/cgi-bin/webhook/send");
url.searchParams.append("key", key);

const response = await fetch(url, {
  method: "POST",
  headers: { "Content-Type": " application/json" },
  body: JSON.stringify({
    msgtype: "text",
    text: { content: "这是一条来自自定义机器人的消息" },
  }),
});

if (!response.ok) {
  console.error(response.statusText);
  Deno.exit(1);
}

const body = await response.json();

if (body.errcode !== 0) {
  console.error(body.errmsg);
  Deno.exit(1);
}

console.log("send success 👌");

deno_wechat_robot's People

Contributors

justjavac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.