Modules@robinpath/telegram
telegram

@robinpath/telegram

0.1.1Node.jsPublic

Telegram Bot API client for sending messages, photos, documents, locations, polls, stickers, and managing chats

Telegram

Telegram Bot API client for sending messages, photos, documents, locations, polls, stickers, and managing chats

Package: @robinpath/telegram | Category: Messaging | Type: Integration

Authentication

telegram.setToken "default" "123456:ABC-DEF..."

Call this once at the start of your script before using any other function. Credentials persist for the duration of the script execution.

Use Cases

Use the telegram module when you need to:

  • Get info about the bot (id, first_name, username) -- Use telegram.getMe to perform this operation
  • Send a text message to a chat -- Use telegram.send to perform this operation
  • Send a photo from a local file to a chat -- Use telegram.sendPhoto to perform this operation
  • Send a document/file from a local path to a chat -- Use telegram.sendDocument to perform this operation
  • Send a GPS location to a chat -- Use telegram.sendLocation to perform this operation

Quick Reference

FunctionDescriptionReturns
setTokenStore a Telegram bot token for subsequent API calls{botId, set}
getMeGet info about the bot (id, first_name, username){id, is_bot, first_name, username}
sendSend a text message to a chatTelegram Message object
sendPhotoSend a photo from a local file to a chatTelegram Message object
sendDocumentSend a document/file from a local path to a chatTelegram Message object
sendLocationSend a GPS location to a chatTelegram Message object
sendPollSend a poll to a chatTelegram Message object with poll
editMessageEdit the text of an existing messageEdited Telegram Message object
deleteMessageDelete a message from a chattrue on success
getUpdatesReceive incoming updates via long pollingArray of Telegram Update objects
sendStickerSend a sticker by file_id to a chatTelegram Message object with sticker
getChatGet up-to-date information about a chatTelegram Chat object

Functions

setToken

Store a Telegram bot token for subsequent API calls

Module: telegram | Returns: object -- {botId, set}

telegram.setToken "default" "123456:ABC-DEF..."
ParameterTypeRequiredDescription
botIdstringNoBot identifier (default: "default")
tokenstringYesTelegram bot token from @BotFather

getMe

Get info about the bot (id, first_name, username)

Module: telegram | Returns: object -- {id, is_bot, first_name, username}

telegram.getMe "default"
ParameterTypeRequiredDescription
botIdstringNoBot identifier (default: "default")

send

Send a text message to a chat

Module: telegram | Returns: object -- Telegram Message object

telegram.send "default" "-100123456" "Hello from RobinPath!"
ParameterTypeRequiredDescription
botIdstringYesBot identifier
chatIdstringYesTarget chat ID or @username
textstringYesMessage text
optionsobjectNo{parseMode?, disableNotification?, replyToMessageId?}

sendPhoto

Send a photo from a local file to a chat

Module: telegram | Returns: object -- Telegram Message object

telegram.sendPhoto "default" "-100123456" "/tmp/photo.jpg" {"caption": "Look at this!"}
ParameterTypeRequiredDescription
botIdstringYesBot identifier
chatIdstringYesTarget chat ID or @username
photoPathstringYesAbsolute path to image file
optionsobjectNo{caption?}

sendDocument

Send a document/file from a local path to a chat

Module: telegram | Returns: object -- Telegram Message object

telegram.sendDocument "default" "-100123456" "/tmp/report.pdf" {"caption": "Monthly report"}
ParameterTypeRequiredDescription
botIdstringYesBot identifier
chatIdstringYesTarget chat ID or @username
filePathstringYesAbsolute path to file
optionsobjectNo{caption?}

sendLocation

Send a GPS location to a chat

Module: telegram | Returns: object -- Telegram Message object

telegram.sendLocation "default" "-100123456" 48.8566 2.3522
ParameterTypeRequiredDescription
botIdstringYesBot identifier
chatIdstringYesTarget chat ID or @username
latitudenumberYesLatitude
longitudenumberYesLongitude

sendPoll

Send a poll to a chat

Module: telegram | Returns: object -- Telegram Message object with poll

telegram.sendPoll "default" "-100123456" "Best language?" ["TypeScript", "Rust", "Go"]
ParameterTypeRequiredDescription
botIdstringYesBot identifier
chatIdstringYesTarget chat ID or @username
questionstringYesPoll question
optionsarrayYesArray of answer option strings

editMessage

Edit the text of an existing message

Module: telegram | Returns: object -- Edited Telegram Message object

telegram.editMessage "default" "-100123456" 42 "Updated text"
ParameterTypeRequiredDescription
botIdstringYesBot identifier
chatIdstringYesChat ID where the message is
messageIdnumberYesID of the message to edit
textstringYesNew message text
optionsobjectNo{parseMode?}

deleteMessage

Delete a message from a chat

Module: telegram | Returns: object -- true on success

telegram.deleteMessage "default" "-100123456" 42
ParameterTypeRequiredDescription
botIdstringYesBot identifier
chatIdstringYesChat ID
messageIdnumberYesID of the message to delete

getUpdates

Receive incoming updates via long polling

Module: telegram | Returns: array -- Array of Telegram Update objects

telegram.getUpdates "default" {"offset": 0, "limit": 10}
ParameterTypeRequiredDescription
botIdstringYesBot identifier
optionsobjectNo{offset?, limit?, timeout?}

sendSticker

Send a sticker by file_id to a chat

Module: telegram | Returns: object -- Telegram Message object with sticker

telegram.sendSticker "default" "-100123456" "CAACAgIAAxk..."
ParameterTypeRequiredDescription
botIdstringYesBot identifier
chatIdstringYesTarget chat ID or @username
stickerIdstringYesSticker file_id

getChat

Get up-to-date information about a chat

Module: telegram | Returns: object -- Telegram Chat object

telegram.getChat "default" "-100123456"
ParameterTypeRequiredDescription
botIdstringYesBot identifier
chatIdstringYesChat ID or @username

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Telegram API error: ${data.description ?? JSON.stringify(data)}Check the error message for details
Bot token is required.Check the error message for details
chatId is required.Check the error message for details
text is required.Check the error message for details
photoPath is required.Check the error message for details
filePath is required.Check the error message for details
question is required.Check the error message for details
At least 2 poll options are required.Check the error message for details
@desc "Get me and validate result"
do
  set $result as telegram.getMe "default"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate Me

Retrieve all items and loop through them.

@desc "Setup authentication"
do
  telegram.setToken $token
enddo

@desc "Get me and iterate results"
do
  set $result as telegram.getMe "default"
  each $item in $result
    print $item
  end
enddo

2. Create a new item with send

Create a new resource and capture the result.

@desc "Setup authentication"
do
  telegram.setToken $token
enddo

@desc "Send"
do
  set $result as telegram.send "default" "-100123456" "Hello from RobinPath!"
  print "Created: " + $result
enddo

3. Create and update workflow

Create an item and then update it.

@desc "Setup authentication"
do
  telegram.setToken $token
enddo

@desc "Send and edit message"
do
  set $created as telegram.send "default" "-100123456" "Hello from RobinPath!"
  # Update the created item
  telegram.editMessage "default" "-100123456" 42 "Updated text"
enddo

4. Check before creating

List existing items and only create if needed.

@desc "Setup authentication"
do
  telegram.setToken $token
enddo

@desc "Get me and send"
do
  set $existing as telegram.getMe "default"
  if $existing == null
    telegram.send "default" "-100123456" "Hello from RobinPath!"
    print "Item created"
  else
    print "Item already exists"
  end
enddo

5. Multi-step Telegram workflow

Chain multiple telegram operations together.

@desc "Setup authentication"
do
  telegram.setToken $token
enddo

@desc "Get me, send, and more"
do
  set $r_getMe as telegram.getMe "default"
  set $r_send as telegram.send "default" "-100123456" "Hello from RobinPath!"
  set $r_sendPhoto as telegram.sendPhoto "default" "-100123456" "/tmp/photo.jpg" {"caption": "Look at this!"}
  print "All operations complete"
enddo

6. Safe getMe with validation

Check results before proceeding.

@desc "Setup authentication"
do
  telegram.setToken $token
enddo

@desc "Get me and validate result"
do
  set $result as telegram.getMe "default"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • slack -- Slack module for complementary functionality
  • discord -- Discord module for complementary functionality
  • teams -- Teams module for complementary functionality
  • whatsapp -- WhatsApp module for complementary functionality
  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/telegram

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size6.1 KB
Versions1
Weekly Downloads23
Total Downloads23
Stars0
Last Publish1 months ago
Created1 months ago