Telegram Bot API

Hi everyone,

has anyone ever tried to use telegram bot to send messages of orders or bills to Telegram channel (group)?

https://api.telegram.org/bot1154477631:AAElHucd6wld0JtEn-YdhuBqqSbC1yAXtf8/sendMessage?chat_id=@username=@message

Ive created a printer, print job, template and automation but it doesnt seem to get sent nor do I receive an error of any kind.

username=SlrPosTickets&text
message=Hi from SambaPOS

If I put the url in browser and manually input my username & message I get a message in my group

https://api.telegram.org/bot1154477631:AAElHucd6wld0JtEn-YdhuBqqSbC1yAXtf8/sendMessage?chat_id=@SlrPosTickets&text=Hello world

1 Like

https://api.telegram.org/bot1154477631:AAElHucd6wld0JtEn-YdhuBqqSbC1yAXtf8/sendMessage?chat_id=@username@=@message@

1 Like

Ill give it a go but ‘&’ in url is usually a start of entity so when you put it in template it cuts off the rest of the text.

username=SlrPosTickets&text
message=Hi from SambaPOS

Though this case doesnt cut it off but still the message isnt delivered.

username=SlrPosTickets&text
message=Hi from SambaPOS

I think I am making some basic syntax mistake…

Bit of playing around I got the right output
image

But for some reasons it never gets sent. Any ideas? Firewall? Port forwarding?

Spaces are not valid in url as I understand.
Think its %20

1 Like

Form data (for GET or POST) is usually encoded as application/x-www-form-urlencoded : this specifies + for spaces.

URLs are encoded as RFC 1738 which specifies %20 .

In theory I think you should have %20 before the ? and + after:

example.com/foo%20bar?foo+bar
1 Like

Yes you are right, but now when I actually put it all together it just crashes SambaPOS.

I am getting frustrated! :persevere:
I appreciate your input though, if you wish feel free to test it yourself. Ill leave it for now, hopefully I will have an eureka moment tomorrow lol

What are you sending?
Being more familier with scripts id be looking at posting from there.
Check and see if their api supports post fields or json/xml data rather than url string.

I am sending a simple url request with 2 entities. Group channel & text it should send.

https://api.telegram.org/bot1154477631:AAElHucd6wld0JtEn-YdhuBqqSbC1yAXtf8/sendMessage?chat_id=*chat_id*&text=*text*
chat_id=*chat_id*&text=*text*

chat_id gets replaced by @SlrPosTickets
text gets replaced by whatever the message is

& separates the entities.

But as I said, the output URL is fine, but when you use the URL printer to send this requests it crashes SambaPOS.

Is it possible that API sends the response and that is what crashes SambaPOS?

I doubt url printer is looking for a response or at least doesnt try and do anything with it.

Seems to wirk easy from script;

Get a response at least, did you get the message, presuming the testing url you showed was to yourself?

Here is that script;

function testtelgram(){
	var chat_id 	= '@SlrPosTickets';
	var message		= 'Hi from SambaPOS';
	var url 		= 'https://api.telegram.org/bot1154477631:AAElHucd6wld0JtEn-YdhuBqqSbC1yAXtf8/sendMessage?chat_id='+chat_id+'&text='+message;
	var request_json = '';
	var response_json = web.PostJson(url,request_json);
	return response_json
}

Was just coppied from other scripts as all mine post json.
Sure there are several webpost helpers and one without json element.
Expect their api likely will have ability to receive the data as post json rather than url vars which would be cleaner script but same functionality. At leasted based on the fact it returned a json success responce

1 Like

Thanks @JTRTech, I appreciate it.

I was hoping to avoid using scripts because I am not sending a fixed message, I am sending new order to Telegram.

I wanted to avoid doing all the order queries :sweat_smile:

Lol scripts don’t mean fixed. My PMS intergration has sent over 1 million charge lines to group hotels PMS is last 4 years, definatly not fixed scripts. I just did fixed to texf as didnt know your variables.

What your event and what you sending?
N
Don’t need to query anything, can pass in variables via the call from the action or many other options.

1 Like

I know, what I meant to say is that I wanted to go with an easy way but it didnt work. :stuck_out_tongue:

On ticket closing rule if status = new it will send {QTY}x {PRODUCT NAME} and order tags. Once I get it to send that, I can easily play with formatting.

Could you show me an example where you pull order/ticket screen variables within your script? I didnt even realise you can do that

If nothing wlse you can push variables in from the CALL

CALL:handler.functionName(’{TICKET NO}’,’{TICKET TOTAL}’)}

function functionName(inputTicketNo,inputTicketTotal){
Bla bla
}

1 Like

You are a legend! Thanks @JTRTech

I like working in scripts, rather than complext string of rules you can use dlg helpers to get vars from user input from the script directly.
My new email guest bill for signature posts ticket to website with getTicket graph json and website renders pdf of the ticket and emails guest copy with link to an esign form.

I am using a few input vars as above with this graph query

https://forum.sambapos.com/t/integrators-graphql-api-guide/14047/265?u=jtrtech

Key thing is to save the ticket before firing script, that way you have ticket id and lots of routes to get data you need.

Slightly gutted get ticket dosnt include payments as could have cut my PMS scripts by at least a 1/3 if switched to graoh query.

1 Like