Send a Message to Microsoft Teams via Databricks
In Microsoft Teams, automated/programmatic messages can be posted via email or via Incoming Webhooks. This article will explain how to send messages to Microsoft Teams via webhooks.

Step 1: Create an incoming webhook.
Right-click on to your favorite channel, choose “Connectors” and click “Configure” next to Incoming Webhook.

Step 2: Send a message to Microsoft Teams using cURL
Testing via cURL will be faster and of course, saves you some money before using Databricks.
The format for Microsoft Teams payload should be
{"text":"your msg"}Put together as Shell Script
$msg="Test Message via cURL"$url="https://webhook.office.com/webhookb2/b9a63247-a...."$curl -H 'Content-Type: application/json' -d '{"text": "'"${msg}"'"}' ${url}After confirming that the message has reached the Teams, let's implement the same using Databricks.
Usecase:
Typical Spark jobs comprise several steps. To know the process status sending message to Teams will be of great help. This is even better when working as a team, so other team members can also follow the channel instead of sending group emails.
Sending a message to Microsoft Teams via Databricks
Scala users:
import scala.sys.process._// json Payload and Scala both supports only double quotes. Thats the reason the message is enclosed within docstring """val msg = """{"text":"Message sent via Databricks / Scala "}"""val webhookUrl = "https://webhook.office.com/webhookb2/b9a67-a58a"// Creating a Sequence variable, so it basically arranges all the values in desired sequence.val sendMessage = Seq("curl", "-H", "Content-Type: application/json", "-d", s"$json",s"${webhookUrl}")// Executing the shell curl command sendMessage.!
pySpark users:
Install pymsteams library in your cluster.

import pymsteams## Please make sure library pymsteams is installed in the cluster.def sendMessageToTeams(webHookUrl: str,msg: str):
try:
# escaping underscores to avoid alerts in italics.
msg = msg.replace('_', '\_')
teams_msg = pymsteams.connectorcard(webHookUrl)
teams_msg.text(f'{msg}')
teams_msg.send()
except Exception as e:
print(f'failed to send alert: {str(e)}')sendMessageToTeams("Message sent via Databricks / Python","https://....)




