Naccl / NBlog

🍓 Spring Boot + Vue 前后端分离博客系统 https://naccl.top

Home Page:https://naccl.top

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

评论发送后,tgbot机器人收不到消息

YunhaiHu opened this issue · comments

commented

大佬,帮我看下,
部署到云服务器上,评论后tgbot机器人收不到消息,不知道什么原因。反向代理url测试没问题可以发消息到tgbot。
https://tg-bot.0x23.cf/bot6062929002:AAHEvQ6zN_mLI4VW9pkHe-l2sNem9RhocrE/sendMessage?chat_id=5418278945&text=123
图片

配置文件的tgbot部分,

blog.api=https://124.221.95.134:8090

tg.bot.api=https://api.telegram.org/bot
tg.bot.token=6062929002:AAHEvQ6zN_mLI4VW9pkHe-l2sNem9RhocrE
tg.bot.chat-id=5418278945
tg.bot.use-proxy=false
tg.bot.use-reverse-proxy=true
tg.bot.reverse-proxy-url=https://tg-bot.0x23.cf

后面是评论后的一部分日志

2023-03-03 18:24:52.841  INFO 21306 --- [       task-142] top.naccl.util.telegram.TelegramUtils    : send2ReverseProxy => reverseProxyUrl: https://tg-bot.0x23.cf
2023-03-03 18:24:52.841  INFO 21306 --- [       task-142] top.naccl.util.telegram.TelegramUtils    : send2ReverseProxy => destUrl: https://api.telegram.org/bot6062929002:AAHEvQ6zN_mLI4VW9pkHe-l2sNem9RhocrE/sendMessage
2023-03-03 18:24:52.842  INFO 21306 --- [       task-142] top.naccl.util.telegram.TelegramUtils    : send2ReverseProxy => response: <200,<!DOCTYPE html>
<html>
<head>
	<!-- UI from here: https://codepen.io/FlorinPop17/pen/dyPvNKK -->
	<title>Telegram Bot API Proxy</title>
	<style type="text/css">
		@import url('https://fonts.googleapis.com/css?family=Muli&display=swap');

		* {
			box-sizing: border-box;
		}

		body {
			background-image: linear-gradient(45deg, #7175da, #9790F2);
			font-family: 'Muli', sans-serif;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			min-height: 100vh;
			margin: 0;
		}

		.courses-container {
			
		}

		.course {
			background-color: #fff;
			border-radius: 10px;
			box-shadow: 0 10px 10px rgba(0, 0, 0, 0.2);
			display: flex;
			max-width: 100%;
			margin: 20px;
			overflow: hidden;
			width: 700px;
		}

		.course h6 {
			opacity: 0.6;
			margin: 0;
			letter-spacing: 1px;
			text-transform: uppercase;
		}

		.course h2 {
			letter-spacing: 1px;
			margin: 10px 0;
		}

		.course-preview {
			background-color: #2A265F;
			color: #fff;
			padding: 30px;
			max-width: 250px;
		}

		.course-preview a {
			color: #fff;
			display: inline-block;
			font-size: 12px;
			opacity: 0.6;
			margin-top: 30px;
			text-decoration: none;
		}

		.course-info {
			padding: 30px;
			position: relative;
			width: 100%;
		}

		.progress-container {
			position: absolute;
			top: 30px;
			right: 30px;
			text-align: right;
			width: 150px;
		}

		.progress {
			background-color: #ddd;
			border-radius: 3px;
			height: 5px;
			width: 100%;
		}

		.progress::after {
			border-radius: 3px;
			background-color: #2A265F;
			content: '';
			position: absolute;
			top: 0;
			left: 0;
			height: 5px;
			width: 66%;
		}

		.progress-text {
			font-size: 10px;
			opacity: 0.6;
			letter-spacing: 1px;
		}

		.btn {
			background-color: #2A265F;
			border: 0;
			border-radius: 50px;
			box-shadow: 0 10px 10px rgba(0, 0, 0, 0.2);
			color: #fff;
			font-size: 16px;
			padding: 12px 25px;
			position: absolute;
			bottom: 15px;
			right: 15px;
			letter-spacing: 1px;
			text-decoration: none;
		}

		#domain {
			cursor: pointer;
		}
	</style>
</head>
<body>
	<div class="courses-container">
		<div class="course">
			<div class="course-preview">
				<h6>Used for</h6>
				<h2>TelegramRC Bot</h2>
				<a href="https://tssaltan.top/?p=1928&utm_source=proxy">About TelegramRC Bot</a>
			</div>
			<div class="course-info">
				<h6>What is it?</h6>
				<h2>Proxy for Telegram Bot API</h2>
				<p>URI for using this proxy: <b id="domain" onclick="selectText(this)">https://tg-bot.0x23.cf/</b></p>
				<a class="btn" href="https://github.com/TsSaltan/Telegram-bot-api-php-proxy">View at GitHub</a>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		function selectText(node) {
		    if (document.body.createTextRange) {
		        const range = document.body.createTextRange();
		        range.moveToElementText(node);
		        range.select();
		    } else if (window.getSelection) {
		        const selection = window.getSelection();
		        const range = document.createRange();
		        range.selectNodeContents(node);
		        selection.removeAllRanges();
		        selection.addRange(range);
		    } else {
		        console.warn("Could not select text in node: Unsupported browser.");
		    }
		}
	</script>
</body>
</html>,[Date:"Fri, 03 Mar 2023 10:24:52 GMT", Content-Type:"text/html; charset=UTF-8", Transfer-Encoding:"chunked", Connection:"keep-alive", vary:"Accept-Encoding", strict-transport-security:"max-age=31536000", CF-Cache-Status:"DYNAMIC", Report-To:"{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=BKy5f6nz%2FPfk9N6LQWedZ5WtfNi5TP4fP%2FKHp02AeGjQZ1FgbUq4siD6OlsVagQLYYO9%2FixdKcrNKSbPiKBwIk46qDlXP6S7MhixtqkoKJDVj1FhMXBqqr1xVh1DHeMI8g%3D%3D"}],"group":"cf-nel","max_age":604800}", NEL:"{"success_fraction":0,"report_to":"cf-nel","max_age":604800}", Server:"cloudflare", CF-RAY:"7a212c1738592ef8-LAX", alt-svc:"h3=":443"; ma=86400, h3-29=":443"; ma=86400"]>

不好意思啊,本项目发送TG消息的请求体格式不太一样,所以通常的反代无法处理,看到你用到了其它开源项目搭建的反代,可能不太好修改,可以参照 blog-api/cfworker-tg-api-open.js 这个 cf worker 脚本,具体POST请求体格式如下:

{
    "to": "https://api.telegram.org/bot1234567890:qwertyuiopasdfghjklzxcvbnm/sendMessage",
    "data": {
        "chat_id": "1234567890",
        "parse_mode": "HTML",
        "text": "123"
    }
}

为了方便可以直接使用我放在 cf worker 上的反代:

tg.bot.use-reverse-proxy=true
tg.bot.reverse-proxy-url=https://tg-api-open.nacccl.top/

也可以使用 blog-api/cfworker-tg-api-open.js 自行在 cf worker 搭建(需要将 Worker 绑定路由至自己的域名)

完整请求 CURL 如下:

curl --location 'https://tg-api-open.nacccl.top/' \
--header 'Content-Type: application/json' \
--data '{
    "to": "https://api.telegram.org/bot1234567890:qwertyuiopasdfghjklzxcvbnm/sendMessage",
    "data": {
        "chat_id": "1234567890",
        "parse_mode": "HTML",
        "text": "123"
    }
}'

另外你暴露了 token,注意修改哦

commented

大佬,懂了好的,感谢