最近看到了Github上面一个开源的项目 PmCenter ,可以通过此项目来搭建一个私聊Bot,解决+86用户不能私聊的问题

此教程仅在Vultr Debian 9 测试通过,不保证其他Linux系统的可用性,不建议使用minimal系统,精简得太厉害



更新了CentOS 7 x64的教程,更加简单,可能是这篇写复杂了,嘻嘻



安装 NET Core SDK

更新以及安装组件

apt-get update && apt-get install unzip curl sudo libunwind8 gettext apt-transport-https

注册产品密钥以及产品源

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/dotnetdev.list'

Install NET Core SDK

sudo apt-get update && sudo apt-get install dotnet-sdk-2.0.0

将 dotnet 添加到 PATH

export PATH=$PATH:$HOME/dotnet

检查是否安装成功

dotnet --version

出现

root@Lula:~# dotnet --version
2.0.0

即安装成功


安装.NET Core Runtime

注册Microsoft密钥和订阅源

wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget -q https://packages.microsoft.com/config/debian/9/prod.list
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list

Install .NET Runtime

sudo apt-get update && sudo apt-get install aspnetcore-runtime-2.2

运行 pmcenter 机器人

拉取源码

mkdir pmcenter
cd pmcenter
wget https://ci.appveyor.com/api/projects/Elepover/pmcenter/artifacts/pmcenter.zip
unzip pmcenter.zip

运行

dotnet pmcenter.dll

第一次运行将会在/root/pmcenter目录下生成pmcenter.json配置文件,修改APIKeyOwnerID以及LangURL后其他使用默认配置即可

配置文件说明

APIKey是Bot的密钥,Botfather里面可以查看
OwnerID为主人TG账号的ID,第三方的TG(Plus message)可以看到,不要弄错了
LangURL是语言文件地址

两份汉化语言文件地址:

正常一点的
https://raw.githubusercontent.com/Elepover/pmcenter/master/locales/pmcenter_locale_zh.json

萌哒哒的
https://raw.githubusercontent.com/Elepover/pmcenter/master/locales/pmcenter_locale_zh.meow.json

设置pmceter开机自启

Debian 9是带有rc.local服务,但是不带/etc/rc.local文件

手工添加一个/etc/rc.local文件


cat <<EOF >/etc/rc.local
    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.
    
    cd /root/pmcenter && dotnet pmcenter.dll
    exit 0
    EOF

然后赋予权限

chmod +x /etc/rc.local

启动接着rc-local服务

systemctl start rc-local

查看状态

systemctl status rc-local

机器人开启后,与Bot的对话中输入/help查看帮助信息

文章名: 《Debian 9 搭建私聊 Telegram Bot》

本文链接:https://lula.fun/687.html

除特别注明外,文章均由 噜啦 原创

 原创文章 转载时请注明 出处 以及文章链接
最后修改:2019 年 12 月 13 日 08 : 45 PM