Upload a file in a Telegram Bot

(Antonio) #1

Hi,
I’m testing the HTTP REQUEST function in my flow in a Telegram bot.
I successfully tested it with the method GET by using a simple PHP scripts (test1.php) that returns if a number is even or odd.
In my flow: first I inserted an ASK a Question for the input of the number then I added a HTTP REQUEST in which I specified in the Request URL: http://www.mydomain.com/test1.php?num={{write_a_number.parsed_answer}}. It woks very fine.

When I try to do the same for the POST method, I cannot understand how to implement it correctly :frowning:
I created another simple PHP script (upload.php) that allow the upload of a file into my server.
How do I have to build the HTTP REQUEST for the POST method, in order to let people upload a file through my telegram bot ?

I hope my question makes sense.
Thanks everyone in advance for your help.
Nino

(Daniel Beckett) #2

Hi @ansfo2013

The webhook docs has more info on how to send data and the different options available. For a POST you’ll need to specify key/values for the data and if applicable, add in any headers.

(Antonio) #3

Hi Daniel,
thanks for your answer.
Following the image about my http request settings.


It still does not work.
When the flow, ask the question to upload a file and I expect the file uploaded is passed to my php scrip; instead the flow continue to wait for the answer to the question until it is interrupted cause abandoned.
Would it be possible to see an example about how to implement it correctly??

Thank you
Nino

(Daniel Beckett) #4

Hi @ansfo2013

Are you using a new file trigger to capture the uploaded file? Ask a Question won’t detect a file being sent to the bot, only a new file trigger.

If you use the new file trigger and then webhook out from that you should be able to get the URL for the uploaded file.

(Antonio) #5

Thanks again,
I would really appreciate a help from you: would you be so kind to show me an example?

(Daniel Beckett) #6

You would need a New File Trigger:

And then a HTTP request (I’m using the GET method where I send the value in the URL, e.g. ?file={{new_file.file_url}})

The last part really depends on what you’re doing at the webhook end point so I can’t really give an example but if I was sending from Flow XO to Flow XO then the output would look something like this:

Upload Image with telegram
(Antonio) #7

Hi Daniel,
in my screen does not appear such a choice you indicated
I see the following choices:

???

(Antonio) #8

how can I implement this??

(Antonio) #9

EUREKA,
Finally I found it !!!
I had to start a new flow! Instead I was trying to add the upload file to my existing flow!!!
Ok, now Telegram api is receiving the upoladed file …

but still does not work ! see the output

What am I missing in the http request settings??

(Antonio) #10

Hi Daniel,
I must be wrong somewhere in my logic.
I do not understand how do I have to set the HTTP Request with post method, in order to let file be uploaded into my server.
The script responsible for the upload work is named “upolad.php”. I pass it, with its complete url path, in the HTTP setting:

then, in the settings, I indicate the file to be uploaded:

So in my bot I attach a file (which is correctly passed to Telegram Api) but I do not find it in my server’s folder where it is supposed to be moved by the php script.

I really do not understand how to proceed.

(Sarah Palombo) #11

From what I can see the URL is taken from the task ‘New file’ and passed into the Make a HTTP Request
In the HTTP settings, you’d use {{new_file.file_url}} rather than {{allega_file.file_url}}

You can always share your flow if this hasn’t helped (support@flowxo.com)

I’ll help :slight_smile:

Sarah

(Antonio) #12

Hi Sarah,
thanks for your reply.
allega_file.file_url is correct because I changed the flow name:


that’s why my Make a HTTP Request settings is:
.

How can I share my flow with you? I did not find any command to do that.

(Karen Barker) #13

Hi @ansfo2013

I see you’ve sent this into our support team so we’ll take this over to email now to try and get to the bottom of the issue :thumbsup:

(Dima Azizbekov) #14

Why this method doesn’t working yet?

(Daniel Beckett) #15

@_dima Which method are you referring to? You can use the New File trigger to capture files. Have you ran into a certain issue with one of your flows?

(Dima Azizbekov) #17

@DanielBeckett I created new flow with Webhook. When Webhook Accepted, I took WebHook Url and than created new flow with new file. Repited all what you did. Whan I checked Interactions of Flow with New File(after sending image to bot direct) in utput I saw “Success” with 200 only. When I checked Global Interactions, there my Flow with Webhook runed too. There I saw “No input and output data”. In your example there must be import URL of my sended Image. I don’t know why your example doesn’t work now. I did it before, but now it doesn’t working. Can you help me with it?

(Daniel Beckett) #18

Sorry, that’s not too clear what’s going wrong. Could you perhaps share some screenshots of the errors that you’ve seen?

If it’s easier, you can email support@flowxo,com and we’ll pick it up from there.

(Dima Azizbekov) #19

@DanielBeckett I sent all about it to your support email.

(Tô Huy) #20

Hi @DanielBeckett,
I user “Make a HTTP Request” for upload image.
But It return ESOCKETTIMEDOUT.



Please help me.

(Tô Huy) #21

Oh, I resolve it. Thanks