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.

Source Distribution

ms-teams-0.1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

ms_teams-0.1.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file ms-teams-0.1.0.tar.gz.

File metadata

  • Download URL: ms-teams-0.1.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for ms-teams-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c9b8c75041e7eb998634f1111bf285512736e771e513cde8566d715379c478ec
MD5 42377c728ab9f75902fc947f44766498
BLAKE2b-256 9803fce6161bb7af9acecc482d7cce7a264bd4244cf6803598902e7eb9f45d59

See more details on using hashes here.

File details

Details for the file ms_teams-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ms_teams-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for ms_teams-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 577920673fd79c374cc8db02e2c6fb9c1fefdf2c2f6d64b233eccbb3e24dd130
MD5 64fea3ec96a346ed88189f8f0ce71644
BLAKE2b-256 7c5ccf03fb041e7be0e58363e3eba5d68cce26c8621b9e9c738fa3f1ea0ac348

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page