Skip to content

Commit

Permalink
feat(send): Photo send
Browse files Browse the repository at this point in the history
  • Loading branch information
indes committed Dec 7, 2018
1 parent 4eb2f80 commit 92caac7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# Changelog
All notable changes to this project will be documented in this file.

## 0.0.2 - 2018-12-07
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.2] - 2018-12-07
### Added
- 增加POST请求方式
- 增加 POST 请求方式
- 增加 Photo 发送功能

### Changed
- 更换 url 路由

## 0.0.1 - 2018-11-26
## [0.0.1] - 2018-11-26
### Added
- 上传基础代码

32 changes: 31 additions & 1 deletion src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
});


$app->map(['GET', 'POST'], "/api/send", function (Request $request, Response $response, array $args) {
$app->map(['GET', 'POST'], "/api/msg", function (Request $request, Response $response, array $args) {

$telegram = new Telegram(getenv('BOT_TOKEN'));
if (getenv('PROXY')) {
Expand All @@ -54,6 +54,36 @@
]);


if ($result->isOk()) {
return $response->withJson(["ok" => true]);
} else {
return $response->withJson($result);
}

});

$app->map(['GET', 'POST'], "/api/photo", function (Request $request, Response $response, array $args) {

$telegram = new Telegram(getenv('BOT_TOKEN'));
if (getenv('PROXY')) {
Longman\TelegramBot\Request::setClient(
new \GuzzleHttp\Client([
'base_uri' => 'https://api.telegram.org',
'proxy' => getenv('PROXY')
])
);
}

$parsedBody = $request->getParsedBody();

$url = $parsedBody["url"] ? $parsedBody["url"] : $request->getQueryParam("url");

$result = Longman\TelegramBot\Request::sendPhoto([
'chat_id' => (int)getenv('OWNER_ID'),
'photo' => $url
]);


if ($result->isOk()) {
return $response->withJson(["ok" => true]);
} else {
Expand Down

0 comments on commit 92caac7

Please sign in to comment.