SendDocument from telegram bot

(Sergey Ponomarenko) #1

Hi everybody,
Here is an example how to sendDocument (attachment) from bot to chat: it is based on a “code” action.
And the code is:

var url = inputs.url;
// I’ve got multiline text from HTTP Get Action on previous step and here is a trick to put it into the variable correctly
var myText = (function () {/{{summary_extraction.result}}

var opts = {
method: ‘POST’,
url: ‘<YOUR_BOT_API_KEY>/sendDocument’,
formData: {
chat_id: {{new_message.channel_id}},
caption: ‘Summary_{{ask_a_question.parsed_answer}}.txt’,
document: {value: myText,
filename: ‘Summary_{{ask_a_question.parsed_answer}}.txt’,
contentType: ‘text/plain’

utils.request(opts, function(err, resp, body) {
if(err) {
return reject(err);

1 Like
(Viktor Rachuk) #2

hi, Sergey! Is it possible to attach pdf file using such method? it will be great if u write the answer to my telegram @Viktor_Rachuk . Thanks a lot

(Sergey Ponomarenko) #3

Yes, surely, it’s possible. Any file you want I suppose. The only moment is how to encode it to pass to javascript variable.

(Hanan Alharbi) #4

could please let me now how or what the code that will help me to send a pdf file please ?