Last active
September 7, 2022 12:11
-
-
Save giacomelli/1c8e405116e1b48a7d25dec9b36edbea to your computer and use it in GitHub Desktop.
Sending a Slackbot message from Unity3d: http://diegogiacomelli.com.br/sending-a-slackbot-message-from-unity3d/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BotController : MonoBehaviour | |
{ | |
private void Start() | |
{ | |
Send("Hello world!"); | |
} | |
/// <summary> | |
/// Sends a message to a Slack channel using the Slackbot API through the chat.postMessage (https://api.slack.com/methods/chat.postMessage) | |
/// </summary> | |
private void Send(string message) | |
{ | |
Debug.Log("Sending message '{0}'...", message); | |
var url = "https://slack.com/api/chat.postMessage"; | |
var data = new WWWForm(); | |
// Create your Slackbot and its API token here: https://my.slack.com/services/new/bot | |
data.AddField("token", "YOUR SLACK BOT API TOKEN"); | |
// The Slack channel. | |
data.AddField("channel", "general"); | |
// How the Slack bot will be identified in Slack. | |
data.AddField("username", "Buildron"); | |
// Your bot icon url image. | |
data.AddField("icon_url", "https://raw.githubusercontent.com/skahal/Buildron/master/docs/images/Buildron-logo-128x128.png"); | |
data.AddField("text", message); | |
var post = new WWW(url, data); | |
StartCoroutine(WaitForPost(post)); | |
} | |
private IEnumerator WaitForPost(WWW post) | |
{ | |
yield return post; | |
Debug.Log("Message sent."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment