Copilot bot for GroupMe SMS

Just opening a thread for this bot.

Hey @flipphoneguy and @Dev-in-the-BM_2.0

The way I made the Colpilot Bot was by having the script repeat the message if there is a + sign and had that mention copilot with a Loci Attachment mentioning the Copilot User ID (128934125)

Note the repeat does not have to say Copilot

You can send me an email if you have any questions

The only thing is that its running in JavaScript and not python, I am sure Ai can convert it for you though

Hey, New update to the Copilot Ai bot - The images are now working and Removed one of the steps from the process. Detailed instructions are on https://copilotimages.netlify.app/ DM me with any questions.

New thing is that a + is no longer required to text ai but if you don’t want ai to reply start with an @ symbol

I never updated from the old one and pictures are still working great and being sent to my email.

Oh, did you change the script at all or you went with the auto generated one from the website?

Additionally did you use the advanced section of the form or you left that part empty?

I didn’t use advanced and didn’t modify the script.

That is interesting because my personal one stopped working as well as multiple other I think @Dev-in-the-BM_2.0 also was not working if I recall correctly, Not sure why

I am working on making a New Integration which involves simply OAuth to your GroupMe account, and your group gets created Automatically and you can text AI. When I am done, I will update everyone.

This version will not involve Images though unless there is someone that wants to make a workspace account that can handle emailing the images to everyone.

1 Like

In case anyone noticed, copilot sms bots broke. All they achieved was getting the message to Copilot and the response would just automatically get delivered to SMS users just like any user or bot message.

This stopped working cuz GroupMe started sending to SMS users “Copilot sent a message. View it here: link” instead of the actual message. Copilot responses also don’t get sent to your webhook in a bot, do you can’t just have the bot echo back any message with copilot’s UID.

I fixed this by having my script resend messages that start with “+” as user mentioning Copilot like till now, wait 2 seconds (from my testing it took between 2+ to 3+ seconds till AI responds), poll every 0.7 seconds (up to 10s) the messages endpoint using the same UID you use to mention Copilot till you get the copilot response, and then echo it back when it arrives.

I’m providing the code I dumped into my bot for context. If you’re not using python, this won’t be extremely helpful but maybe something

COPILOT_FIRST_DELAY = 2.0
COPILOT_POLL_INTERVAL = 0.7
COPILOT_POLL_DEADLINE = 12  # give up after this many seconds


def schedule_copilot_echo(token, group_id, bot_id, since_id):
    if not (token and bot_id and since_id):
        return
    deadline = time.time() + COPILOT_POLL_DEADLINE
    threading.Timer(COPILOT_FIRST_DELAY, _poll_copilot_echo, args=(token, group_id, bot_id, since_id, deadline)).start()

def _poll_copilot_echo(token, group_id, bot_id, since_id, deadline):
    try:
        r = requests.get(f"https://api.groupme.com/v3/groups/{group_id}/messages", params={"token": token, "since_id": since_id, "limit": 20})
        msgs = r.json().get("response", {}).get("messages", []) if r.ok else []
        cop = sorted([m for m in msgs if m.get("user_id") == COPILOT_UID], key=lambda m: m["created_at"])
        if cop:
            bot_send(bot_id, cop[0].get("text"))
            return
    except Exception:
        pass
    if time.time() < deadline:
        threading.Timer(COPILOT_POLL_INTERVAL, _poll_copilot_echo, args=(token, group_id, bot_id, since_id, deadline)).start()

The since_id is taken from my user_send function (which sends a message as a user and can also mention) which returns the following after making a request to send a message

return response.json()['response']['message']['id']

You should make sure you use threading in python or whatever your language offers rather then just sleeping cuz sleeping is a waste of time :joy:

If you just paste this into AI, it should be able to spit out some js for gas. @Shalom_Karr you may wanna fix your bot.

1 Like

One day - thanks though - will bookmark this to remind me in a few weeks

2 Likes

When you do it will it get updated to old bots or I will have create a new bot?