1.2.5 โ€ข Published 2 years ago

@dreamcoder-uzbek/telegramjs v1.2.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

NPM

About The Project

This project was created to facilitate communication with Telegram using javascript

Add for Node js project(ReactJs)

  • npm
npm install @dreamcoder-uzbek/telegramjs
  • yarn
yarn add @dreamcoder-uzbek/telegramjs

Add to project via CDN link

https://cdn.jsdelivr.net/npm/@dreamcoder-uzbek/telegramjs@1.2.4/dist/telegram.min.js
https://unpkg.com/@dreamcoder-uzbek/telegramjs@1.2.4/dist/telegram.min.js

Add to project for browser

<html>
  <head>
    <title>Telegram Js | Connection example</title>
    <script src="dist/telegram.min.js"></script>
  </head>
<body>
<script>
  // your js code...
</script>
</body>
</html>

This is a complete guide to using this library. After reading it, you will be able to use it. I hope it will be useful for you


Getting Started

First of all, a special object is created to use the library. it will be possible to connect to the library using the telegram keyword

const connected = new telegram.init(botToken, chatId, parseMode);
Keywordrequireddefault
botTokenyes
chatIdyes
parseModeoptionalMarkdown

Usage

getMe

A simple method for testing your bot's authentication token. Requires no parameters. Returns basic information about the bot in form of a User object.

getUpdates

Use this method to receive incoming updates using long polling (wiki). Returns an Array of Update objects.

getFile

ParameterTypeRequiredDescription
file_idStringYesFile identifier to get information about

See here for more information

sendMessage

Use this method to send text messages. On success, the sent Message is returned.

connected.sendMessage(text, reply_to_message_id, protect_content, disable_notification);
ParameterTypeRequiredDescription
textStringyesText of the message to be sent, 1-4096 characters after entities parsing
reply_to_message_idIntegeroptionalIf the message is a reply, ID of the original message
protect_contentBooleanoptionalProtects the contents of the sent message from forwarding and saving
disable_notificationBooleanoptionalSends the message silently. Users will receive a notification with no sound.

Markdown

Please note:

  • Entities must not be nested, use parse mode MarkdownV2 instead.
  • There is no way to specify underline and strikethrough entities, use parse mode MarkdownV2 instead.
  • To escape characters _, *, `, [ outside of an entity, prepend the characters '\' before them.
  • Escaping inside entities is not allowed, so entity must be closed first and reopened again: use _snake_\__case_ for italic snake_case and *2*\**2=4* for bold 2*2=4.

MarkdownV2

Please note:

  • Any character with code between 1 and 126 inclusively can be escaped anywhere with a preceding '\' character, in which case it is treated as an ordinary character and not a part of the markup. This implies that '\' character usually must be escaped with a preceding '\' character.
  • Inside pre and code entities, all '`' and '\' characters must be escaped with a preceding '\' character.
  • Inside (...) part of inline link definition, all ) and \ must be escaped with a preceding '\' character.
  • In all other places characters _, *, [, ], (, ), ~, `, >, #, +, -, =, |, {, }, ., ! must be escaped with the preceding character '\'.
  • In case of ambiguity between italic and underline entities __ is always greadily treated from left to right as beginning or end of underline entity, so instead of ___italic underline___ use ___italic underline_\r__, where \r is a character with code 13, which will be ignored

HTML

  <b>bold</b>, <strong>bold</strong>
  <i>italic</i>, <em>italic</em>
  <u>underline</u>, <ins>underline</ins>
  <s>strikethrough</s>, <strike>strikethrough</strike>, <del>strikethrough</del>
  <span class="tg-spoiler">spoiler</span>, <tg-spoiler>spoiler</tg-spoiler>
  <b>bold <i>italic bold <s>italic bold strikethrough <span class="tg-spoiler">italic bold strikethrough spoiler</span></s> <u>underline italic bold</u></i> bold</b>
  <a href="http://www.example.com/">inline URL</a>
  <a href="tg://user?id=123456789">inline mention of a user</a>
  <code>inline fixed-width code</code>
  <pre>pre-formatted fixed-width code block</pre>
  <pre><code class="language-javascript">pre-formatted fixed-width code block written in the Javascript programming language</code></pre>

Please note:

  • Only the tags mentioned above are currently supported.
  • All <, > and & symbols that are not a part of a tag or an HTML entity must be replaced with the corresponding HTML entities (< with &lt;, > with &gt; and & with &amp;).
  • All numerical HTML entities are supported.
  • The API currently supports only the following named HTML entities: &lt;, &gt;, &amp; and &quot;.
  • Use nested pre and code tags, to define programming language for pre entity.
  • Programming language can't be specified for standalone code tags.

sendPhoto

connected.sendPhoto(photo, caption, disable_notification = false, protect_content = false, reply_to_message_id);
ParameterTypeRequiredDescription
photoInputFile or StringyesPhoto to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. The photo must be at most 10 MB in size. The photo's width and height must not exceed 10000 in total. Width and height ratio must be at most 20. More information on Sending Files ยป
captionStringoptionalPhoto caption (may also be used when resending photos by file_id), 0-1024 characters after entities parsing
reply_to_message_idIntegeroptionalIf the message is a reply, ID of the original message
disable_notificationBooleanoptionalSends the message silently. Users will receive a notification with no sound.
protect_contentBooleanoptionalProtects the contents of the sent message from forwarding and saving

Methods with the same properties as sendPhoto

sendPhoto, sendVideo,sendDocument, sendAudio,sendAnimation, sendVideoNote,

sendPoll

connected.sendPoll(question, options, correct_option_id, is_anonymous, explanation, type, reply_to_message_id, disable_notification, protect_content)
ParametersTypeRequiredDescription
questionStringyesPoll question, 1-300 characters
optionsArray of StringyesA JSON-serialized list of answer options, 2-10 strings 1-100 characters each
correct_option_idIntegerOptional0-based identifier of the correct answer option, required for polls in quiz mode
is_anonymousBooleanOptionalTrue, if the poll needs to be anonymous, defaults to True
typeStringOptionalPoll type, quiz or regular, defaults to regular
explanationStringOptionalText that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing
reply_to_message_idIntegerOptionalIf the message is a reply, ID of the original message
disable_notificationBooleanoptionalSends the message silently. Users will receive a notification with no sound.
protect_contentBooleanoptionalProtects the contents of the sent message from forwarding and saving

sendDice

connected.sendDice(emoji, disable_notification, protect_content, reply_to_message_id)
ParametersTypeRequiredDescription
emojiStringOptionalEmoji on which the dice throw animation is based. Currently, must be one of โ€œ๐ŸŽฒโ€, โ€œ๐ŸŽฏโ€, โ€œ๐Ÿ€โ€, โ€œโšฝโ€, โ€œ๐ŸŽณโ€, or โ€œ๐ŸŽฐโ€. Dice can have values 1-6 for โ€œ๐ŸŽฒโ€, โ€œ๐ŸŽฏโ€ and โ€œ๐ŸŽณโ€, values 1-5 for โ€œ๐Ÿ€โ€ and โ€œโšฝโ€, and values 1-64 for โ€œ๐ŸŽฐโ€. Defaults to โ€œ๐ŸŽฒโ€
reply_to_message_idIntegerOptionalIf the message is a reply, ID of the original message
disable_notificationBooleanoptionalSends the message silently. Users will receive a notification with no sound.
protect_contentBooleanoptionalProtects the contents of the sent message from forwarding and saving

sendLocation

connected.sendLocation (latitude, longitude, horizontal_accuracy, disable_notification = false, protect_content = false, reply_to_message_id)
ParametersTypeRequiredDescription
latitudeFloat numberYesLatitude of the location
longitudeFloat numberYesLongitude of the location
reply_to_message_idIntegerOptionalIf the message is a reply, ID of the original message
disable_notificationBooleanoptionalSends the message silently. Users will receive a notification with no sound.
protect_contentBooleanoptionalProtects the contents of the sent message from forwarding and saving

sendContact

connected.sendContact (phone_number, first_name, last_name, disable_notification, protect_content, reply_to_message_id)
ParametersTypeRequiredDescription
phone_numberStringYesContact's phone number
first_nameStringYesContact's first number
last_nameStringOptionalContact's last number
reply_to_message_idIntegerOptionalIf the message is a reply, ID of the original message
disable_notificationBooleanoptionalSends the message silently. Users will receive a notification with no sound.
protect_contentBooleanoptionalProtects the contents of the sent message from forwarding and saving
1.2.5

2 years ago

1.2.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago