Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

How to open multiple rtmbots on the server? #28

Open
mtermoul opened this issue Nov 2, 2015 · 6 comments
Open

How to open multiple rtmbots on the server? #28

mtermoul opened this issue Nov 2, 2015 · 6 comments
Labels

Comments

@mtermoul
Copy link

mtermoul commented Nov 2, 2015

Well, I am trying to have a server that have multiple rtmbots. Each one will have it's own websocket that connects to one team/client.
However in the main loop, I see that you can only open one websocket to the client specified in the .conf token.
Is there a way to open multiple RTM connection dynamically at runtime?

@dmilleravid
Copy link

I would love to see an answer to this question. I am going through the same thing.

mtermoul - did you figure this out?

@abenbecker
Copy link
Contributor

I have multiple running on one server. Each one gets its own socket on start up. I put them all into different folders (rtm1, rtm2, etc) and daemonize them so that they run under different pids.

@rvanlaar
Copy link

No, it's not possible, we rewrote RTMbot to allow multiple teams from one python process.
Do be aware that RTMbot crashes hard when a team removes the bot from slack.

@MeLight
Copy link

MeLight commented Aug 9, 2017

Yes, you can do that, no problem. First, to run a bot programmatically (instead of command line) you do this:

from rtmbot import RtmBot

config = {
    "SLACK_TOKEN": "xoxb-xxxxxxxx-jhgasjhgajhsska",
    "ACTIVE_PLUGINS": [],
}

bot = RtmBot(config)
bot.start()

After that, it's simple to make it multi-threaded:

import time
import threading
from rtmbot import RtmBot

SLACK_TOKEN = "xoxb-111111111-nnnnnnnnnnnnnn"
def start_bot(slack_token):
	config = {
	    "SLACK_TOKEN": slack_token,
	    "ACTIVE_PLUGINS": [],
	}

	bot = RtmBot(config)
	bot.start()

#running the bot in a thread. You can make an array of threads and tokens to run the bot for multiple teams
bot_thread = threading.Thread(target=start_bot, args=(SLACK_TOKEN,))
bot_thread .daemon = True        # we need this to CTRL+C 
bot_thread .start()

# running a loop that prevents from the main process ending
while True:
	time.sleep(1)
	print("slept")

@Roach
Copy link
Contributor

Roach commented Mar 30, 2018

@MeLight nice! Want to add those instructions to the README?

@MeLight
Copy link

MeLight commented Apr 10, 2018

@Roach opened a pull request with README changes

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants