view bots/bigastbot.py @ 0:96f842f12121

start
author drewp@bigasterisk.com
date Tue, 28 Jan 2025 23:30:02 -0800
parents
children 2a288d2cb88c
line wrap: on
line source

import zulip
from kubernetes import client, config

config.load_kube_config()


def get_secret_api_key(email: str) -> str:
    api = client.CoreV1Api()
    secret = api.read_namespaced_secret('zulip-api-secrets', 'default')
    secret_key = email.replace('@', '.')
    return secret.data[secret_key]  # type: ignore


class BigAstBot:

    def __init__(self, email: str):

        class Options:
            zulip_api_key = get_secret_api_key(email)
            zulip_email = email
            zulip_site = 'https://chat.bigasterisk.com'
            cert_bundle = None
            client_cert = None
            client_cert_key = None
            insecure = False
            verbose = True
            zulip_client = None
            zulip_config_file = None

        self.zulip_client = zulip.init_from_options(Options())

    def send_to_channel(self, channelName: str, topic: str, content: str):
        msg = dict(type="stream",
                   to=[channelName],
                   topic=topic,
                   content=content)
        return self.zulip_client.send_message(msg)