Script to send order information to Telegram

I am looking on a guide on how to use a script to send my order information (order info on ticket). If anyone can point out how to use the script feature in automation to send order information using the telegram api instead of print url would be very helpful.

Take a look at my pms intergration

Although allot could be done using graphql rather than the direct sql as that wasn’t available when I did it.

1 Like

How would i pass a variable from a ticket to the script? Ex : kot number?

Just search telegram api on the forum. It’s all there.

ok i have figured out how to use scripts to use the telegram bot. but only difficulty i am current having is passing order details. any simple way to pass QUANTITY, ITEMNAME of all items in the ticket?

Depends on what format is needed at the other end, could try using a report expression to feed data into script but as said depends on required format at api endpoint relative to your use, not enough info to say for sure.

function TestTelegram(DELIVERYAGENT,TICKETNO,TICKETTOTAL,CUSTOMERNAME,CUSTOMERADDRESS,CUSTOMERCONTACT,CUSTOMERVIBER)
{
var chat_id = ‘xxx’;
var message = “Delivery Agent : “+DELIVERYAGENT+”\n”+“Ticket No : “+TICKETNO+”\n”+“Ticket Total : MVR “+TICKETTOTAL+”\n”+“Customer Name : “+CUSTOMERNAME+”\n”+“Customer Address : “+CUSTOMERADDRESS+”\n”+“Customer Contact No : “+CUSTOMERCONTACT+”\n”+"Customer Viber No : "+CUSTOMERVIBER;
var url = 'https://api.telegram.org/botxxx/sendMessage?chat_id=’+chat_id+’&text=’+message;
var request_json = ‘’;
var response_json = web.PostJson(url,request_json);
return response_json
}

I want to send the Order information from the ticket via the telegram bot but i am unable to pass order information from automation. If possible can you please share an expression i can use to pass the order details such same as its displayed in KOT print to the script?

So you want to sent the entire order? Each item, and the quantity? It looks like telegram supports HTML format, but no breakline option. I have a feeling it would be very hard to read. It looks like they support image uploads, so that might be a better option. Maybe you should better explain what you’re going for.

I’m thinking the URL printer might be better in this case. You’ll have access to the all the ticket data, you can format it how you want and then send it via the HTTP get request.

There are not tons of examples, but if you search the site you’ll find some.

Report order details expression from reports likely help.

JTR, do those expressions work on new tickets/new orders or only tickets whose information is committed to the database?

No report tags only work on submitted tickets.

1 Like

Report ticket expressions do I beleive.
Solution would be to save ticket before running script where required. Not suitable in all cases but examples like this where are sending details to external system would typically want to be ‘confirmed’ data anyway.

1 Like

{ORDER DETAILS:x} tag works with unsaved tickets.

1 Like

That would be a specific order on an order linked automation event though I beleive, rather than able to return whole ticket of orders.

Nope, it returns whole ticket, {ORDER DETAILS:O.MenuItemName} do the trick

1 Like

Interesting, wish knew that before :slight_smile:

1 Like

Are you sure though, pretty sure when tried that at least in the past it acted as a report and returned all period tickets… were you trying on test dB or with no other tickets?