python-rtmbot icon indicating copy to clipboard operation
python-rtmbot copied to clipboard

How to open multiple rtmbots on the server?

Open mtermoul opened this issue 10 years ago • 6 comments

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?

mtermoul avatar Nov 02 '15 14:11 mtermoul

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

mtermoul - did you figure this out?

dmilleravid avatar Apr 11 '16 22:04 dmilleravid

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.

abenbecker avatar Apr 13 '16 15:04 abenbecker

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.

rvanlaar avatar Oct 16 '16 13:10 rvanlaar

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")

MeLight avatar Aug 09 '17 11:08 MeLight

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

Roach avatar Mar 30 '18 22:03 Roach

@Roach opened a pull request with README changes

MeLight avatar Apr 10 '18 07:04 MeLight