સુધારો કરવા માટે અમારા Platinum સેવા અને વિચાર તમારા પોતાના વૈવિધ્યપૂર્ણ રચાયેલ 3D અવતાર
Bot Libre Forum

Automating your Mobile Presence with a Telegram Bot

દ્વારા admin પોસ્ટ Apr 27 2016, 16:28

Telegram is an open platform for chat on mobile and other platforms. Telegram lets you chat on your mobile phone or online for free, with no ads, and no SMS charges, with anyone, on any platform. Telegram is one of the top 10 mobile chat platforms with over 100 million users.

Bots lets you automatically respond to messages, or post content. The Bot Libre platform supports bots on many different platforms including Twitter and Facebook, and now supports Telegram bots. Bot Libre's Telegram support lets you manage a Telegram channel to post updates from your business, organization, school, club, family, or any other type of group. Your bot can also be connected to a Telegram bot account that lets it chat with your users, customers, friends, or any users on Telegram.

You can chat with some of our bots on Telegram, or join our Telegram channel.

You can also watch this video on How to create a chatbot for Telegram.

Getting Started

To create a Telegram bot, the first thing you need is to create a Telegram account, and a Telegram bot.

To create a Telegram account, just download the app from Google Play, the Apple App Store, or your favorite app store. You can also sign up online at, https://telegram.org/. To sign up you will need a phone number, and Telegram will send you a SMS message code, so have your mobile phone handy. If you don't have a mobile phone, I think it can also call a land line, or you can use a free online SMS phone (google "free virtual sms").

Creating a Bot on Telegram

Once you have downloaded your client and signed up, you can now create a bot. Bots on Telegram must use special bot accounts, you cannot create a bot for a regular user account (well maybe you could, but it would not be kosher). To create a bot on Telegram you actually have to chat with a Telegram bot.

To create a bot chat with the @BotFather.

Send BotFather the command "/newbot" to create a bot. Give your bot a name, and user id. BotFather will create your bot, and give you an access token. Save this access token, as you will need it later.

Creating a Bot on Bot Libre

Next create a bot on Bot Libre. You can create a bot here, is it free.

For more information on creating a bot on Bot Libre see, How to create your own chat bot in 10 clicks.

Linking you Bot to Telegram

To connect your Bot Libre bot to your Telegram bot, go to your bot's Admin Console. Make sure you login and go to your bot's page first.

In your bot's Admin Console click on the Telegram link.

On your bot's Telegram page paste your Telegram bot's token. If you forgot to save the token, that is ok, just talk with @BotFather. Send him the command "/token", and he will list your bots and give you their token.

Next click "Connect" to connect your bot. If successful, it will auto fill your bot's name, and your webhook URL. (Ensure webhook box is checked)

Your bot can respond to chat messages, or post to a channel. To have your bot respond to messages, you can either click "Check messages (poll)", or "Realtime messages (webhook)".

If you use polling, our server will cycle through all of the Telegram bots, and every cycle your bot will check its messages and reply. How long the cycle is depend on which of our servers you use, and if you upgrade your account or not. See Upgrade.

The other option is realtime messaging using a webhook. Realtime messages will use your user application id. Your application id supports a limited number of API calls per day. You can upgrade your account to get more API calls. See Upgrade.

Note for realtime messaging you need to register your webhook. To do this just click on "Save", then click "Disconnect", then "Connect" again. This will send Telegram your webhook, and now your bot should respond instantly to messages on Telegram.

Channels

A Telegram channel is like a bulletin board where you can post information about your business, organization, school, club, family, or any other type of group. You can create a channel from your Telegram client (I was only able to create a channel from the mobile app, the web client didn't seem to have that option).

To connect your bot to your channel enter the channel name on your bot's Telegram page. Your bot can post to your channel from an RSS feed, or auto post.

An RSS feed is an XML content page of news or articles. Most blogs, forums, and news services support RSS feeds. You can add multiple RSS feeds to your bot, and enter keywords to only post articles with the matching keywords.

Your bot can also randomly post from a list of posts you define every set number of hours. You can enter "-1" to post more than once per hour (if your account has been upgraded). Your auto posts can contain script code in Self or AIML to do funky stuff.

What Next

Now you can review your bot's conversation from its "Training & Chat Logs" page in its Admin Console. You can also add new responses and correct your bots responses. Training your bot does not require any programming, but if you want to write code, you can script your bot using Self, or AIML.

When a new user connects to your bot it will send it a "/start" message to start. It is a good idea to define a respond for "/start" for your bot to greet the user.

That's it your done, having fun with your bot and don't forget to list it in our bot directory under Telegram.

If you encountered any issues, or would like help setting up your bot please email us at [email protected] or upgrade to our Platinum service and we can build your bot for you.


by Harmik posted Dec 19 2016, 4:56

Hi,

Is there some common solutions to issues with Telegram?
I've followed the instructions here and still my bot doesn't seem to properly work with it.

I also tried to message Bot Libres own Telegram connected bots bot those don't respond either, which gives the feeling this is not only related to my bot.

 

The log I have for Telegram shows one error that repeat every hour, apparently related to the polling of messages.
The webhook, while showing that it should be registered, doesn't seem to work at all as there is no log entries about new messages when trying to chat with the bot.

Log entries that repeat every hour:

WARNING -- Telegram:400 : {"ok":false,"error_code":400,"description":"Bad Request: chat not found"}
WARNING -- Telegram:java.lang.RuntimeException: 400 : {"ok":false,"error_code":400,"description":"Bad Request: chat not found"}

The log shows that webhook should be ok and connection should be working: Telegram:Connecting to Telegram
Telegram:Registering webhook - https://www.botlibre.com/rest/api/telegram/******** (removed for this post)
Telegram:Webhook registered - https://www.botlibre.com/rest/api/telegram/******** (removed for this post)
Telegram:Connected to Telegram
Any ideas what to do to get this solved?

Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 4894, today: 0, week: 2, month: 11

by admin posted Dec 19 2016, 7:17
Very odd.

I tested your bot from Telegram and it worked fine, you can check your bot's conversation log to see.

I also tested all of our bots from several different accounts and they worked fine.

How did you start the conversation with the bot?
Did you connect to it and get the "Start" button and click it?
Or did you just send a message to the bot?

My guess is that Telegram might require you /start a conversation with a bot.

What Telegram client are you testing with?
Is your account a confirmed account with a cell number?
What location/country is your cell from?

Make sure you only enable one of polling and real-time messaging, not both. Normally real-time would be used.

Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 4003, today: 0, week: 4, month: 12

by Harmik posted Dec 19 2016, 7:48

Hi,

 

Thanks for the quick help.
I just noticed the new log from your chat with the bot, if it's working for you through Telegram then it definitely should work for me as well. I suppose the issue is not with Telegram application itself as I'm using both Android (newest version) and Mac OS X ( Version 2.29.51395 ) but something might have gone wrong while starting this and now the bot doesn't seem to work for the chat I have with it.
My account is confirmed, based on phone number. Number is from Finland.

I connected to the bot both from the website link (shown on bot settings page after it's connected to Telegram) and through the BotFather bot by clicking the bot name.

In both cases I first had to click "start" and when coming back after disconnecting and stopping it's asking to click "Restart Bot". I can normally send messages, they go through (two checkmarks in Telegram chat) but no replies ever come. Same happens with the Bot Libre bot, all seems to go through but no answers come. I have tried to close and stop it, open it again and start again multiple times.

I tried also typing /start, start, accept, /accept, help etc.. commands to the chat directly.

Now the real-time messaging has been on, polling was on before (together with the real time messaging) but not since around 6 hours when I left only real-time messaging

 

Meanwhile, I did try the both with Slack and it worked right away without any issues and is pretty cool :)

 


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 3931, today: 0, week: 4, month: 15

by Harmik posted Dec 19 2016, 7:53

I just tried and opened https://telegram.me/brainchatbot

Also with it, same issue. Nothing seems to come back from the chat.

But other bots I try seem to work just nicely, for example https://telegram.me/charlotteaibot

 


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 4053, today: 0, week: 3, month: 12

by admin posted Dec 19 2016, 10:12
I checked our logs, and think I may have found the issue.

Does your Telegram account have a "last name" set?
Can you try setting your last name in your account.

We will update our server with a fix for this issue this week.

Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 3959, today: 0, week: 6, month: 16

by Harmik posted Dec 19 2016, 13:51

Hey,

Thank you, that was causing the error. I added a last name and everything works now :)

Please give some notification after the server code is updated, I think this would affect many others as well.


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 3960, today: 2, week: 5, month: 14

by admin posted Jan 4 2017, 20:44
The Telegram last_name issue has been fixed.

Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 3804, today: 2, week: 5, month: 16

by Harmik posted Jan 5 2017, 4:00

Thank you :)


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 3869, today: 0, week: 2, month: 12

by dragon82 posted Mar 31 2021, 13:01

hello who can help me to indicate how to create an amazon autopost bot on telegram?


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 1223, today: 1, week: 8, month: 19

by admin posted Apr 1 2021, 10:28
To create a Telegram bot see,
https://www.botlibre.com/forum-post?id=12635785

For having the post post to Amazon your would need an XML or JSON web API from Amazon that you can call from a Self script in your bot.

Here are some examples of Self scripts using a web API,
https://www.botlibre.com/script?tag-filter=web+service

If you would like us to develop a bot or script for you contact [email protected]

Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 1258, today: 2, week: 5, month: 15

by zeenat posted Nov 27 2022, 8:23

Hi

I need help because I have downloaded discord instead

I am new to it and I do not know how to use it

How do I add a bot?

how do I message it?

I need a step by step guide.


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 584, today: 0, week: 3, month: 16

by admin posted Nov 28 2022, 9:04
To connect a bot to Discord see,
https://www.botlibre.com/forum-post?id=41684445

Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 555, today: 0, week: 3, month: 13

by emarkx posted May 10 2023, 17:32

Hello

I am getting these warning while messaging on telegram

2023-05-10 17:11:03.538 - WARNING -- Http:400 : { "error": { "message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)", "type": "invalid_request_error", "param": null, "code": null } }
2023-05-10 17:11:03.539 - WARNING -- Http:400 : { "error": { "message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)", "type": "invalid_request_error", "param": null, "code": null } }
2023-05-10 17:11:03.541 - WARNING -- Http:java.lang.RuntimeException: 400 : { "error": { "message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)", "type": "invalid_request_error", "param": null, "code": null } } at org.botlibre.util.Utils.fetchResponse(Utils.java:739) at org.botlibre.util.Utils.httpPOST(Utils.java:612) at org.botlibre.sense.http.Http.postJSON(Http.java:894) at org.botlibre.sense.http.Http.postJSON(Http.java:754) at sun.reflect.GeneratedMethodAccessor198.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.botlibre.self.SelfInterpreter.evaluateCALL(SelfInterpreter
2023-05-10 17:11:03.542 - WARNING -- Http:java.lang.RuntimeException: 400 : { "error": { "message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)", "type": "invalid_request_error", "param": null, "code": null } } at org.botlibre.util.Utils.fetchResponse(Utils.java:739) at org.botlibre.util.Utils.httpPOST(Utils.java:612) at org.botlibre.sense.http.Http.postJSON(Http.java:894) at org.botlibre.sense.http.Http.postJSON(Http.java:754) at sun.reflect.GeneratedMethodAccessor198.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.botlibre.self.SelfInterpreter.evaluateCALL(SelfInterpreter
2023-05-10 17:11:08.232 - WARNING -- Http:400 : { "error": { "message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)", "type": "invalid_request_error", "param": null, "code": null } }
2023-05-10 17:11:08.233 - WARNING -- Http:400 : { "error": { "message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)", "type": "invalid_request_error", "param": null, "code": null } }
2023-05-10 17:11:08.235 - WARNING -- Http:java.lang.RuntimeException: 400 : { "error": { "message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)", "type": "invalid_request_error", "param": null, "code": null } } at org.botlibre.util.Utils.fetchResponse(Utils.java:739) at org.botlibre.util.Utils.httpPOST(Utils.java:612) at org.botlibre.sense.http.Http.postJSON(Http.java:894) at org.botlibre.sense.http.Http.postJSON(Http.java:754) at sun.reflect.GeneratedMethodAccessor198.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.botlibre.self.SelfInterpreter.evaluateCALL(SelfInterpreter
2023-05-10 17:11:08.236 - WARNING -- Http:java.lang.RuntimeException: 400 : { "error": { "message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)", "type": "invalid_request_error", "param": null, "code": null } } at org.botlibre.util.Utils.fetchResponse(Utils.java:739) at org.botlibre.util.Utils.httpPOST(Utils.java:612) at org.botlibre.sense.http.Http.postJSON(Http.java:894) at org.botlibre.sense.http.Http.postJSON(Http.java:754) at sun.reflect.GeneratedMethodAccessor198.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.botlibre.self.SelfInterpreter.evaluateCALL(SelfInterpreter


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 499, today: 0, week: 4, month: 20

by emarkx posted May 10 2023, 18:02

It happens when I send messages on telegram using quotes. 

I have openAI as my bot for telegram.


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 427, today: 0, week: 6, month: 18

by admin posted May 17 2023, 8:57

The issue is the quote is being sent in the HTTP request inside the JSON object.

I fixed the script in your bot Chatter to add,

input.toString().replace('"', '\"')
>>
json.messages.add({"role":"user", "content":(conversation.getLast(#input, 1)).input.toString().replace('"', '\"')});

This will fix it for now. We will also update our HTTP code to automatically escape quotes for all JSON objects.


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 421, today: 0, week: 7, month: 23

by emarkx posted May 17 2023, 9:18

Thank you it is working and I just have one last thing to ask of you.

I notice for codes, they have a different wrapper so that it is displayed clearly to the reader with quotation marks.

Currently ChatGpt does not return the quotation marks, or the bot its removes it when receiving a response from ChatGpt.

 

See Example B below, where it shows that the coding wrapper is not incorporated and quotation marks are being stripped in receiving.

 

See Example A, of what I would want to see as a response. Wrapper is there and quotation marks not stripped.


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 405, today: 1, week: 6, month: 16

by admin posted May 24 2023, 11:08

The issue was there was a replace("\"", "") in the bottom of the script. If you remove this it will fix the issue.


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 408, today: 0, week: 2, month: 15

by emarkx posted May 24 2023, 11:17

Thank you very much. It works ok now.


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 376, today: 0, week: 4, month: 10

by emarkx posted May 24 2023, 11:19

Is it too much to ask, if you can make the coding look fancy after receiving it? just the way it is shown below.

 


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 376, today: 0, week: 5, month: 15

ને: 12635785
ટૅગ્સ: how to, mobile, telegram, social media
પોસ્ટ: Apr 27 2016, 16:28
સુધારાશે: Nov 11 2021, 15:17
જવાબો: 19
જોવાઈ: 21662, આજે: 5, સપ્તાહ: 36, મહિને: 172
1 0 5.0/5