Skip to content

Commit

Permalink
Update code examples to use new Deno APIs (#881)
Browse files Browse the repository at this point in the history
* Update code examples to use new Deno APIs

* Merge
  • Loading branch information
rojvv authored Jul 26, 2023
1 parent b0c4ddf commit 982e875
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 30 deletions.
3 changes: 1 addition & 2 deletions site/docs/es/hosting/deno-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ El resultado de este tutorial [puede verse en nuestro repositorio de bots de eje
2. Crea un archivo llamado `mod.ts` o `mod.js`, o en realidad cualquier nombre que te guste (pero deberías recordar y usar este como el archivo principal para desplegar), con el siguiente contenido:

```ts
import { serve } from "https://deno.land/std/http/server.ts";
import { Bot, webhookCallback } from "https://deno.land/x/grammy/mod.ts";
// Puedes modificar esto a la forma correcta de importar tu objeto `Bot`.
import bot from "./bot.ts";

const handleUpdate = webhookCallback(bot, "std/http");

serve(async (req) => {
Deno.serve(async (req) => {
if (req.method === "POST") {
const url = new URL(req.url);
if (url.pathname.slice(1) === bot.token) {
Expand Down
3 changes: 1 addition & 2 deletions site/docs/es/hosting/fly.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ Puedes ejecutar tu bot usando ambos [webhooks o long polling](../guide/deploymen
::: code-group

```ts{11} [Deno]
import { serve } from "https://deno.land/std/http/server.ts";
import { webhookCallback } from "https://deno.land/x/grammy/mod.ts";
// Podrías modificar esto a la forma correcta de importar tu objeto `Bot`.
import { bot } from "./bot.ts";
const port = 8000;
const handleUpdate = webhookCallback(bot, "std/http");
serve(async (req) => {
Deno.serve(async (req) => {
const url = new URL(req.url);
if (req.method === "POST" && url.pathname.slice(1) === bot.token) {
try {
Expand Down
3 changes: 1 addition & 2 deletions site/docs/es/hosting/supabase.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Una vez que hayas creado un proyecto de Supabase Function, puedes escribir tu bo
Puedes utilizar este breve ejemplo de bot como punto de partida.

```ts
import { serve } from "https://deno.land/std/http/server.ts";
import { Bot, webhookCallback } from "https://deno.land/x/grammy/mod.ts";

const token = Deno.env.get("BOT_TOKEN");
Expand All @@ -49,7 +48,7 @@ bot.command("ping", (ctx) => ctx.reply(`¡Pong! ${new Date()}`));

const handleUpdate = webhookCallback(bot, "std/http");

serve(async (req) => {
Deno.serve(async (req) => {
try {
const url = new URL(req.url);
if (url.searchParams.get("secret") !== bot.token) {
Expand Down
3 changes: 1 addition & 2 deletions site/docs/hosting/deno-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ The result of this tutorial [can be seen in our example bots repository](https:/
2. Create a file named `mod.ts` or `mod.js`, or actually any name you like (but you should be remembering and using this as the main file to deploy), with the following content:

```ts
import { serve } from "https://deno.land/std/http/server.ts";
import { webhookCallback } from "https://deno.land/x/grammy/mod.ts";
// You might modify this to the correct way to import your `Bot` object.
import bot from "./bot.ts";

const handleUpdate = webhookCallback(bot, "std/http");

serve(async (req) => {
Deno.serve(async (req) => {
if (req.method === "POST") {
const url = new URL(req.url);
if (url.pathname.slice(1) === bot.token) {
Expand Down
3 changes: 1 addition & 2 deletions site/docs/hosting/fly.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ You can run your bot using both [webhooks or long polling](../guide/deployment-t
::: code-group

```ts{11} [Deno]
import { serve } from "https://deno.land/std/http/server.ts";
import { webhookCallback } from "https://deno.land/x/grammy/mod.ts";
// You might modify this to the correct way to import your `Bot` object.
import { bot } from "./bot.ts";
const port = 8000;
const handleUpdate = webhookCallback(bot, "std/http");
serve(async (req) => {
Deno.serve(async (req) => {
const url = new URL(req.url);
if (req.method === "POST" && url.pathname.slice(1) === bot.token) {
try {
Expand Down
3 changes: 1 addition & 2 deletions site/docs/hosting/supabase.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Once you have created a Supabase Function project, you can write your bot.
You can use this short example bot as a starting point.

```ts
import { serve } from "https://deno.land/std/http/server.ts";
import { Bot, webhookCallback } from "https://deno.land/x/grammy/mod.ts";

const token = Deno.env.get("BOT_TOKEN");
Expand All @@ -49,7 +48,7 @@ bot.command("ping", (ctx) => ctx.reply(`Pong! ${new Date()}`));

const handleUpdate = webhookCallback(bot, "std/http");

serve(async (req) => {
Deno.serve(async (req) => {
try {
const url = new URL(req.url);
if (url.searchParams.get("secret") !== bot.token) {
Expand Down
3 changes: 1 addition & 2 deletions site/docs/id/hosting/deno-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ Hasil dari tutorial disini dapat dilihat di [repositori bot kami](https://github
2. Buat sebuah file dengan nama `mod.ts` atau `mod.js`, ataupun nama lainnya sesuai dengan keinginanmu (tetapi kamu harus mengingatnya karena nanti file tersebut akan digunakan sebagai file deploy utama). File tersebut berisikan:

```ts
import { serve } from "https://deno.land/std/http/server.ts";
import { webhookCallback } from "https://deno.land/x/grammy/mod.ts";
// Kamu mungkin perlu mengubah ini agar dapat melakukan import pada object bot-mu.
import bot from "./bot.ts";

const handleUpdate = webhookCallback(bot, "std/http");

serve(async (req) => {
Deno.serve(async (req) => {
if (req.method === "POST") {
const url = new URL(req.url);
if (url.pathname.slice(1) === bot.token) {
Expand Down
3 changes: 1 addition & 2 deletions site/docs/id/hosting/fly.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ Kamu bisa menjalankan bot menggunakan [webhooks ataupun long polling](../guide/d
::: code-group

```ts{11} [Deno]
import { serve } from "https://deno.land/std/http/server.ts";
import { webhookCallback } from "https://deno.land/x/grammy/mod.ts";
// Kamu mungkin perlu mengubah ini agar object bot-mu bisa di-import.
import { bot } from "./bot.ts";
const port = 8000;
const handleUpdate = webhookCallback(bot, "std/http");
serve(async (req) => {
Deno.serve(async (req) => {
const url = new URL(req.url);
if (req.method === "POST" && url.pathname.slice(1) === bot.token) {
try {
Expand Down
3 changes: 1 addition & 2 deletions site/docs/id/hosting/supabase.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Setelah berhasil membuat sebuah proyek Supabase Function, sekarang kamu bisa men
Kamu bisa menggunakan contoh bot singkat ini sebagai entry point-nya.

```ts
import { serve } from "https://deno.land/std/http/server.ts";
import { Bot, webhookCallback } from "https://deno.land/x/grammy/mod.ts";

const token = Deno.env.get("BOT_TOKEN");
Expand All @@ -53,7 +52,7 @@ bot.command("ping", (ctx) => ctx.reply(`Pong! ${new Date()}`));

const handleUpdate = webhookCallback(bot, "std/http");

serve(async (req) => {
Deno.serve(async (req) => {
try {
const url = new URL(req.url);
if (url.searchParams.get("secret") !== bot.token) {
Expand Down
3 changes: 1 addition & 2 deletions site/docs/uk/hosting/deno-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ Deno Deploy ідеально підходить для більшості про
2. Створіть файл з назвою `mod.ts` або `mod.js` або насправді будь-якою назвою, яку ви хочете, але ви повинні памʼятати та використовувати його як головний файл для розгортання, із наступним вмістом:

```ts
import { serve } from "https://deno.land/std/http/server.ts";
import { webhookCallback } from "https://deno.land/x/grammy/mod.ts";
// Ви можете змінити це на правильний спосіб імпорту вашого обʼєкта `Bot`.
import bot from "./bot.ts";

const handleUpdate = webhookCallback(bot, "std/http");

serve(async (req) => {
Deno.serve(async (req) => {
if (req.method === "POST") {
const url = new URL(req.url);
if (url.pathname.slice(1) === bot.token) {
Expand Down
3 changes: 1 addition & 2 deletions site/docs/uk/hosting/fly.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ next: false
::: code-group

```ts{11} [Deno]
import { serve } from "https://deno.land/std/http/server.ts";
import { webhookCallback } from "https://deno.land/x/grammy/mod.ts";
// Ви можете змінити це на правильний спосіб імпорту вашого обʼєкта `Bot`.
import { bot } from "./bot.ts";
const port = 8000;
const handleUpdate = webhookCallback(bot, "std/http");
serve(async (req) => {
Deno.serve(async (req) => {
const url = new URL(req.url);
if (req.method === "POST" && url.pathname.slice(1) === bot.token) {
try {
Expand Down
3 changes: 1 addition & 2 deletions site/docs/uk/hosting/supabase.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ supabase functions new telegram-bot
Для початку ви можете скористатися цим простим прикладом бота.

```ts
import { serve } from "https://deno.land/std/http/server.ts";
import { Bot, webhookCallback } from "https://deno.land/x/grammy/mod.ts";

const token = Deno.env.get("BOT_TOKEN");
Expand All @@ -49,7 +48,7 @@ bot.command("ping", (ctx) => ctx.reply(`Понг! ${new Date()}`));

const handleUpdate = webhookCallback(bot, "std/http");

serve(async (req) => {
Deno.serve(async (req) => {
try {
const url = new URL(req.url);
if (url.searchParams.get("secret") !== bot.token) {
Expand Down
3 changes: 1 addition & 2 deletions site/docs/zh/hosting/deno-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ Deno Deploy 是大多数简单 bot 的理想选择,并且你应该注意,Den
2. 创建一个名为 `mod.ts``mod.js` 的文件,或任何你喜欢的名字(但你应该记住并使用这个文件作为部署的主要文件),其内容如下:

```ts
import { serve } from "https://deno.land/std/http/server.ts";
import { webhookCallback } from "https://deno.land/x/grammy/mod.ts";
// 你可以将其修改为正确的方式来导入你的 `Bot` 对象。
import bot from "./bot.ts";

const handleUpdate = webhookCallback(bot, "std/http");

serve(async (req) => {
Deno.serve(async (req) => {
if (req.method === "POST") {
const url = new URL(req.url);
if (url.pathname.slice(1) === bot.token) {
Expand Down
3 changes: 1 addition & 2 deletions site/docs/zh/hosting/fly.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ next: false
::: code-group

```ts{11} [Deno]
import { serve } from "https://deno.land/std/http/server.ts";
import { webhookCallback } from "https://deno.land/x/grammy/mod.ts";
// 你可以将其修改为导入 `Bot` 对象的正确方式
import { bot } from "./bot.ts";
const port = 8000;
const handleUpdate = webhookCallback(bot, "std/http");
serve(async (req) => {
Deno.serve(async (req) => {
const url = new URL(req.url);
if (req.method === "POST" && url.pathname.slice(1) === bot.token) {
try {
Expand Down
3 changes: 1 addition & 2 deletions site/docs/zh/hosting/supabase.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ supabase functions new telegram-bot
你可以使用这个简单的示例 bot 作为一个起点。

```ts
import { serve } from "https://deno.land/std/http/server.ts";
import { Bot, webhookCallback } from "https://deno.land/x/grammy/mod.ts";

const token = Deno.env.get("BOT_TOKEN");
Expand All @@ -49,7 +48,7 @@ bot.command("ping", (ctx) => ctx.reply(`Pong! ${new Date()}`));

const handleUpdate = webhookCallback(bot, "std/http");

serve(async (req) => {
Deno.serve(async (req) => {
try {
const url = new URL(req.url);
if (url.searchParams.get("secret") !== bot.token) {
Expand Down

0 comments on commit 982e875

Please sign in to comment.