Giter Club home page Giter Club logo

tgmessage's Introduction

TG Bot

TG 消息推送机器人,基于 vercel 函数搭建的TG消息推送机器人,无需服务器。

搭建教程

建立 TG 机器人

1.首先关注 BotFather

  1. 创建机器人,关注 BotFather 之后,发送 /newboot 开始创建 Bot 第一次输入机器人名称,第二次输入机器人 username 需要以 bot 结尾 oEENc.png

3.获取机器人 token

创建成功之后会发送一条消息给你,里面就包含了 token

oEGEr.png

设置机器人 Command 设置获取 token 命令 首先给 BotFather 发送 /mybots,然后点击你刚才创建的机器人,再点击 Edit Bot, 继续点击 Edit Commands。 然后输入

token - 获取token

这样就设置好了一个 commands

oEQIM.png oE0FG.png oEcR1.png oEd9I.png

克隆本仓库

上面创建好机器人之后,fork 本参考到你的 github 里面 需要修改一个文件配置. api/index.php 主要是修改 机器人 token ,在 38 行,把 token 换成你的机器人 token 可以通过 github 在线编辑代码直接修改。

oEYyF.png

创建 Vercel

Vercel:https://vercel.com/
可以直接使用 github 账户登录 创建好了账户之后在控制台选择 New Project

oE2El.png

然后找到你 fork 的仓库,点击 import,就会自动部署了。

oEXhB.png

部署成功之后,会有免费的域名,然后接下来设置机器人的 webhook.

oEIjK.png

设置 WebHook

设置机器人 webhook, 把下面的 token 和 域名换成你的(把{}去掉), 然后执行 `curl

curl --location --request POST 'https://api.telegram.org/bot{你的token}/setWebhook' \
--form 'url="https://{你的域名}/api?type=webhook"'

参考文档:https://core.telegram.org/bots/api#setwebhook

php 执行 set webhook 脚本

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.telegram.org/bot{你的token}/setWebhook',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => array('url' => 'https://{你的域名}/api?type=webhook'),
));

$response = curl_exec($curl);

tgmessage's People

Contributors

anhao avatar

Watchers

James Cloos 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.