Random message passing on Telegram

I am trying to create a bot, that lists the last 10 messages from Telegram group (Successful), and then select a random message among them. I thought maybe I could do it using random function. The random function gives me a random number between 1 to 10 that will help me in randomly selecting a message. But I am not able to understand how do I pull the message based on that number? I understand I need to somehow create an array containing all the bundle numbers and messages, then use this random function to return a bundle number, message corresponding to that bundle number will be returned. But I am not able to create such array. Please help me on how to pull the chat from the randomly selected bundle number.


Welcome to the Make community!

When you have multiple bundles and want just one item, you can use an Array Aggregator first to combine them into an array, then use the shuffle-first functions.

If you already have an array, then just use the shuffle-first functions directly. You can put this in a Set Variable module if you need a module to put these functions in.

{{ first(shuffle(array)) }}

Hope this helps! Let me know if there are any further questions or issues.

β€” @samliew

3 Likes

Thank you for your support. It works now :heart_eyes:

Couple of points if you can help please:

  1. Is it possible to reply to a certain text on Telegram? I mean tagging the user and then sending the text? Currently, I am able to send the random text in the grp, but it sends it as standalone, not tagging the user/replying to the text. I tried using update id as input to the original message id, but it gave error saying message not found.
  2. I am using ChatGPT to send responses in a grp. Is it possible to get ChatGPT to somehow not repeat the the same output it gave earlier?
  3. Is it possible to somehow feed array into chatgpt? I want to send it recent 10 messages that I am fetching through Tg bot, and then generate a reply to one of them using all 10 as reference. I tried to give array as input to it but the input to chatgpt only picks up the first element of the array.

No problem, glad I could help!

I’d appreciate it if you can create a separate thread per question. This is because I may not be able to answer all the questions, and I also may not be available to answer follow-up questions quickly. It also helps keep this forum organised and easy to search for answers to individual questions.

1. If anyone has a new question in the future, please start a new thread. This makes it easier for others with the same problem to search for the answers to specific questions, and you are more likely to receive help since newer questions are monitored closely.

2. The Make Community guidelines encourages users to try to mark helpful replies as solutions to help keep the Community organized.

This marks the topic as solved, so that:

  • others can save time when catching up with the latest activity here, and
  • allows others to quickly jump to the solution if they come across the same problem

To do this, simply click the checkbox at the bottom of the post that answers your question:
Screenshot_2023-10-04_161049

3. Don’t forget to like and bookmark this topic so you can get back to it easily in future!

Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I found these useful when I was learning Make, and hope they might benefit you too β€”

Getting Started

Help Centre Basics

Articles & Videos

Partner & Custom Apps

Hope this helps! Let me know if there are any further questions or issues.

β€” @samliew

Thank you. I have created separate threads for all the questions.