Skip to content

Instantly share code, notes, and snippets.

@rsatrio
Created September 11, 2022 17:57
Show Gist options
  • Save rsatrio/7b1e004c1b485e11c62ff7edd18565ba to your computer and use it in GitHub Desktop.
Save rsatrio/7b1e004c1b485e11c62ff7edd18565ba to your computer and use it in GitHub Desktop.
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import kong.unirest.Unirest;
@RestController
@RequestMapping("/send-to-telegram")
public class SendToTelegramController {
@Value( "${telegram.chat.id}" )
private String telegramChatId;
@Value( "${telegram.bot.id}" )
private String telegramBotId;
@PostMapping("/")
public ResponseEntity<?> home(@RequestBody String request) {
String urlTelegram="https://api.telegram.org/bot"+telegramBotId+"/sendMessage";
Unirest.get(urlTelegram)
.queryString("chat_id", telegramChatId)
.queryString("text",request).asString().getBody();
return ResponseEntity.ok("ok");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment