Skip to main content

Helper library to construct microsoft teams connector cards

Project description

Build Status

ms-teams

Helper library to construct microsoft teams connector card messages.

This library supports building:

  1. Legacy Message Card
  2. Adaptive Message Card (Not yet supported in teams connector)

Usage

Legacy Message Card

Let's build below message card using ms-teams library.

Message Card

# imports
from msteams.messagecard.fact import Fact
from msteams.messagecard.section import Section
from msteams.messagecard.card import MessageCard

# Create Activity Section
activity_section = Section()\
	.activity_group(activity_image='https://www.shareicon.net/data/32x32/2016/07/16/634601_python_512x512.png',
	                activity_title='Description',
	                activity_text='Helper library to construct microsoft teams connector card messages')\
	.build()

# Add activity section to the message card
message_card = MessageCard().title('ms-teams')\
    .summary('Helper library to construct microsoft teams connector card messages')\
    .theme_color('FF0000')\
    .section(activity_section)

# Create facts
pkg_info = Section()\
    .fact(Fact('URL', 'https://github.com/HarshadRanganathan/ms-teams').build())\
    .fact(Fact('AUTHOR', 'Harshad Ranganathan').build())\
    .build()

# Add facts to the message card and construct the message
payload = message_card.section(pkg_info).build()

Adaptive Card

You can use Card Playground to craft your adaptive cards and build your messages.

Refer Adaptive Card Schema for authoring your cards.

Let's build below adaptive card using ms-teams library.

Adaptive Card

# imports
from msteams.adaptivecard.elements.image import Image
from msteams.adaptivecard.elements.text_block import TextBlock
from msteams.adaptivecard.containers.column import Column
from msteams.adaptivecard.containers.column_set import ColumnSet
from msteams.adaptivecard.containers.container import Container
from msteams.adaptivecard.containers.fact_set import FactSet
from msteams.adaptivecard.containers.fact import Fact
from msteams.adaptivecard.card import AdaptiveCard

# Create Title using TextBlock (Displays text, allowing control over font sizes, weight, and color.)
title = TextBlock('ms-teams').separator(True).size('Medium').weight('Bolder').build()

# Create Activity Block (Image, Title, Subtitle)
activity_image = Image('https://www.shareicon.net/data/32x32/2016/07/16/634601_python_512x512.png').style('Person').size('small').build()
activity_title = TextBlock('Description').weight('Bolder').wrap(True).build()
activity_text = TextBlock('Helper library to construct microsoft teams connector card messages').spacing('None').wrap(True).build()

# Create ColumnSet which allows elements to sit side-by-side
activity_image_col = Column('auto').element(activity_image).build()
activity_text_col = Column('stretch').element(activity_title).element(activity_text).build()
activity_grp = ColumnSet().column(activity_image_col).column(activity_text_col).build()

# Create Container to group items together
header = Container().element(title).element(activity_grp).build()

# Add the container to the adaptive card
adaptive_card = AdaptiveCard().container(header)

# Add series of facts to the Container
pkg_info = Container()

basic = FactSet(separator=True)\
    .fact(Fact('URL', 'https://github.com/HarshadRanganathan/ms-teams').build()) \
    .fact(Fact('AUTHOR', 'Harshad Ranganathan').build()) \
    .fact(Fact('LICENSE', 'MIT').build()) \
    .build()

keywords = FactSet(separator=True) \
    .fact(Fact('KEYWORDS', 'Microsoft Teams').build()) \
    .build()

classifiers = FactSet(separator=True) \
    .fact(Fact('CLASSIFIERS', 'Programming Language :: Python :: 3.7\n\n'
                              'License :: OSI Approved :: MIT License\n\n'
                              'Operating System :: OS Independent').build()) \
    .build()

pkg_info.element(basic)
pkg_info.element(keywords)
pkg_info.element(classifiers)

# Build the container
body = pkg_info.build()

# Add facts container to the adaptive card and generate the payload message
payload = adaptive_card.container(body).build()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ms-teams, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size ms_teams-0.1.0-py3-none-any.whl (11.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size ms-teams-0.1.0.tar.gz (6.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page