Skip to content

Commit

Permalink
feat(Message send): Add post method
Browse files Browse the repository at this point in the history
  • Loading branch information
indes committed Dec 7, 2018
1 parent 8ad05ca commit 4eb2f80
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

## 0.0.2 - 2018-12-07
### Added
- 增加POST请求方式

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ php -S localhost:8080 -t public
## 使用
```
curl -X GET http://<your_url>:<port>/api/send?msg=HelloWorld
```
```
19 changes: 15 additions & 4 deletions src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
return $response;
});

$app->get("/api/send", function (Request $request, Response $response, array $args) {

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

$telegram = new Telegram(getenv('BOT_TOKEN'));
if (getenv('PROXY')) {
Expand All @@ -43,10 +44,20 @@
);
}

$parsedBody = $request->getParsedBody();

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

$result = Longman\TelegramBot\Request::sendMessage([
'chat_id' => (int)getenv('OWNER_ID'),
'text' => $request->getQueryParam("msg")
'text' => $text
]);
$response->getBody()->write("ok");
return $response;


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

});

0 comments on commit 4eb2f80

Please sign in to comment.