Skip to content

Instantly share code, notes, and snippets.

@nzlosh
Created October 30, 2017 07:42
Show Gist options
  • Save nzlosh/8230a9c41cdfb5d59df5845a390840dc to your computer and use it in GitHub Desktop.
Save nzlosh/8230a9c41cdfb5d59df5845a390840dc to your computer and use it in GitHub Desktop.
Plugin to test send card in multipart of slack backend.
[Core]
name = Test Slack Attachment
module = .
[Documentation]
description = Test slack attachments message split.
[Python]
version = 3
from errbot import BotPlugin, botcmd, arg_botcmd, webhook
import logging
LOG = logging.getLogger(__name__)
class TestSlackAttachment(BotPlugin):
def __init__(self, bot, name):
super(TestSlackAttachment, self).__init__(bot, name)
@botcmd(split_args_with=None)
def testcard(self, message, args):
"""
testcard <username> <no. of chars> (number of chars in kilo. e.g 1 == 1k chars)
"""
to_id = self.build_identifier(args[0])
msg_size = int(args[1])
self.post_message(
"".join(["{}".format(i)*int((1024/len(str(i)))) for i in range(1,msg_size+1)]),
to_id
)
def post_message(self, message, to_id):
kwargs = {
"body": message,
"to": to_id,
"summary": "This is a test for multi-part card posts.",
"title": "Multi-part card post",
"link": "http://errbot.io/en/latest/",
"image": "http://errbot.io/en/latest/_static/errbot.png",
"thumbnail": "http://errbot.io/en/latest/_static/errbot.png",
"color": "#a000a0",
"fields": [
("field1", "text1"),
("field2", "text2")
]
}
self.send_card(**kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment