{"id":15658911,"url":"https://github.com/dcdunkan/telegraph","last_synced_at":"2025-04-28T17:19:34.231Z","repository":{"id":44632756,"uuid":"446810046","full_name":"dcdunkan/telegraph","owner":"dcdunkan","description":"Telegra.ph API wrapper for JavaScript","archived":false,"fork":false,"pushed_at":"2024-06-07T06:18:19.000Z","size":47,"stargazers_count":26,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T06:11:18.484Z","etag":null,"topics":["deno","telegraph","telegraph-api","typescript"],"latest_commit_sha":null,"homepage":"https://jsr.io/@dcdunkan/telegraph","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dcdunkan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-11T12:21:36.000Z","updated_at":"2025-02-17T14:14:46.000Z","dependencies_parsed_at":"2024-06-07T04:29:53.934Z","dependency_job_id":"d99a4262-5be6-4f91-8ac2-cab38bebbcad","html_url":"https://github.com/dcdunkan/telegraph","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"60940adf3624066108198c21d394c383f00d2743"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdunkan%2Ftelegraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdunkan%2Ftelegraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdunkan%2Ftelegraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdunkan%2Ftelegraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcdunkan","download_url":"https://codeload.github.com/dcdunkan/telegraph/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250976118,"owners_count":21516878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","telegraph","telegraph-api","typescript"],"created_at":"2024-10-03T13:14:24.108Z","updated_at":"2025-04-28T17:19:34.200Z","avatar_url":"https://github.com/dcdunkan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Telegraph\n\n[![JSR Version](https://jsr.io/badges/@dcdunkan/telegraph)](https://jsr.io/@dcdunkan/telegraph)\n[![JSR Score](https://jsr.io/badges/@dcdunkan/telegraph/score)](https://jsr.io/@dcdunkan/telegraph/score)\n\nTelegraph API wrapper with additional support for uploading media and\nHTML/Markdown content formatting.\n\n#### What is Telegraph?\n\n\u003e Telegra.ph is a minimalist publishing tool that allows you to create richly\n\u003e formatted posts and push them to the Web in just a click. Telegraph posts also\n\u003e get beautiful [Instant View](https://telegram.org/blog/instant-view) pages on\n\u003e [Telegram](https://telegram.org).\n\u003e\n\u003e _from official API documentation._\n\nIt is highly recommended to read the official documentation by Telegram Team.\n\n- [Telegraph API Documentation](https://telegra.ph/api)\n- [API Reference](https://jsr.io/@dcdunkan/telegraph/doc)\n\nImport from the module:\n\n```ts\nimport { Telegraph } from \"jsr:@dcdunkan/telegraph\";\n```\n\n## Example Usage\n\nHere is a small demonstration of how you can create an account and create a page\nusing the Markdown format.\n\n```ts\nimport { parse, Telegraph } from \"jsr:@dcdunkan/telegraph\";\n\nconst telegraph = new Telegraph(\n  {\n    token: \"\", // pass in a token if you have one\n    apiRoot: \"https://api.graph.org\", // change the api root if you need to\n  },\n);\n\n// If you don't already have an access token, create one!\nconst account = await telegraph.createAccount({ short_name: \"John\" });\n// Assign the access token to the instance.\ntelegraph.token = account.access_token;\n\nconst content = `\\\nI created this page using and [Telegraph](https://github.com/dcdunkan/telegraph)\nlibrary. You can also create one with just a few lines of code.\n\nSee the [GitHub Repository](https://github.com/dcdunkan/telegraph) for more.`;\n\n// Now that you have set a token, let's create a page.\nconst page = await telegraph.create({\n  title: \"My Telegraph Post\",\n  content: parse(content, \"Markdown\"),\n});\n\nconsole.log(page); // logs information about the page we just created.\n```\n\nTry other methods as well. The official documentation is also available in your\neditor! Simply hover your mouse over the methods and properties to see their\ndocumentation.\n\nThe default API root URL is **\u003chttps://api.telegra.ph\u003e**. You can change it in\nthe options if you want to.\n\n## Content Formatting\n\nWith Telegraph API, you can only create articles using the Node format, which is\nrelatively hard to use and work on compared to plain text formats. This library\nprovides helpers functions to deal with this. HTML and Markdown are supported\nout-of-the-box using the `parse` method.\n\n```ts\nimport { parse } from \"jsr:@dcdunkan/telegraph\";\n\nconst markdown = parse(`**Something in Markdown**`, \"Markdown\");\nconst html = parse(`\u003ch1\u003eSome heading in HTML\u003c/h1\u003e`, \"HTML\");\n```\n\n\u003e [!NOTE]\n\u003e\n\u003e - Markdown parsing uses the default configuration of\n\u003e   [marked](https://github.com/markedjs/marked).\n\u003e - HTML is using [deno-dom](https://github.com/b-fuze/deno-dom)\n\u003e\n\u003e Markdown is first transformed to HTML and parsed to Node format.\n\nThe returned array of `Node` the `parse` function can then be used to create\ncontent.\n\n#### \"Can I use other Markdown specifications?\"\n\nYes, you can. Default configuration of **[marked](https://npm.im/marked)** is\nused for the markdown parsing. If you wish to use some other, you can just parse\nit to HTML first and then `parse` with HTML as parse mode.\n\n(uses \u003chttps://jsr.io/@deno/gfm\u003e as an example:)\n\n```ts\nimport { parse } from \"jsr:@dcdunkan/telegraph\";\nimport { render } from \"jsr:@deno/gfm\";\n\nconst html = render(\"Some GFM markdown\");\nconst content = parse(html); // tada :D\n// use `content` for creating pages.\n```\n\n## Upload Media Files\n\nThere is an undocumented API endpoint for uploading media files to Telegraph\nservers. A helper function for uploading local media files to this endpoint is\nalso included in this library.\n\n\u003e **Note**: As far as I know, this API only allows you to upload a limited set\n\u003e of media types: gif, png, png, mp4, jpg, and jpeg of limited size, around 6\n\u003e MB. **Do not ask questions regarding these, as I do not know anything more**.\n\n```ts\nimport { upload } from \"jsr:@dcdunkan/telegraph\";\n\nconst file = await Deno.readFile(\"./image.png\");\nawait upload(file); // returns url of the uploaded file\n\n// The following also works:\nawait upload(\"https://some.temporary-link-servi.ce/1234.gif\");\nawait upload(new URL(\"...\"));\nawait upload({ url: \"...\", otherProps: {} });\n\nconst response = await fetch(\"file:///home/user/file.png\");\nawait upload(response); // Response\nawait upload(await response.blob()); // Blob\nawait upload(await response.bytes()); // Uint8Array\n\nconst file = await Deno.open(\"./video.gif\");\nawait upload(file.readable); // ReadableStream\u003cUint8Array\u003e\nawait upload(file.readable[Symbol.asyncIterator]()); // AsyncIterable\u003cUint8Array\u003e, also sync ones!\n```\n\nAPI URL can also be changed for uploading files:\n\n```ts\nawait upload(data, \"https://graph.org/upload\");\n```\n\nIt defaults to \u003chttps://telegra.ph/upload\u003e.\n\n\u003e **Just don't misuse the free service.**\n\n#### \"Why can't I just pass in the local filepath?\"\n\nFor the ease of shipping for multiple runtimes. You can always have local files\nuploaded by opening them by yourselves and passing the stream/content to the\nupload helper. You can even `fetch` using `file:///` protocol and pass the\nresponse to get the file uploaded.\n\n---\n\nIf you are having issues with the library, you can report it by\n[opening an issue](https://github.com/dcdunkan/telegraph/issues).\n\n[Licensed under MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcdunkan%2Ftelegraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcdunkan%2Ftelegraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcdunkan%2Ftelegraph/lists"}