Skip to content

Send Slack Message

Our Messaging API designed to fullfill most of your use cases and can be easily integrate to any of the system. We can send single message to both private and public channel in your workspace by adding the channel as slack in messaging API. The D7Messaging App should be added to your workspace before sending slack messages.

POST
/messages/v1/send

Authentication

AUTHORIZATION: Bearer Token

Request parameters

Parameter Value / Pattern
*work_space_name Workspace name to send message. D7Messaging App should be added to the workspace here.
*channel_name Channel name to send message. To send a message to a channel, you can provide the channel name for both public and private channels. For public channels, simply specify the channel name. However, for private channels, you'll need to grant access to the D7Messaging App by using the command "/invite @D7Messaging".
*content The message content is being sent. Now you can only send text messages through this API
*channel To select the messaging channel that you want to use. (e.g., slack, SMS etc.)
report_url To receive delivery status (DLR) for your slack message, specify the callback server URL where you want to receive the slack message status updates using the report_url parameter. When the delivery status changes, the status updates will be sent to the specified URL. For information on the format of the DLR message, please refer to the "Receiving DLR" section.

Response

When the request is validated, request_id, status and created time will be returned. Users can use this request_id to query status using the Get status endpoint.

200 - Success
{
    "request_id": "d9835609-a4e0-10ea-a26a-eeafbe700fef",
    "status": "accepted",
    "created_at": "2001-08-05T12:52:38.393Z"
}
401 - Unauthorized
{ 
    "detail": { 
    "code": "ACCESS_TOKEN_SIGNATURE_VERIFICATION_FAILED",
    "message": "It looks like your requests were failed due to a missing or invalid 'Access Token'. Sign up at https://app.d7networks.com and create an authentication token in the developer section."
    } 
} 
422 - Validation Error
{
    "detail": [
        {
            "loc": [
            "string"
            ],
        "msg": "string",
        "type": "string"
        }
    ]
} 

Response Parameters

Parameter Value / Pattern
request_id Unique id for each Slack request. This request_id is required to check delivery status of your Slack.
status The status of Slack request. Possible request status are accepted and rejected
created_at Date and time of the Slack request.

Examples:

Send Message to your workspace

curl --location 'https://api.d7networks.com/messages/v1/send' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{api_access_token}}' \
--data '{
"message_globals": {
    "report_url": "https://the_url_to_recieve_delivery_report.com"
},
"messages": [
    {
    "channel": "slack",
    "content": "Greetings from D7 API",
    "work_space_name":"WorkspaceName",
    "channel_name": "ChannelName"
    }
]
}'
npm i direct7
const Client = require('direct7')

const client = new Client(apiToken="Your API token")

const response = await client.slack.sendSlackMessage({
            content : 'Hello, this is a test message!',
            work_space_name : 'WoekSpaceName',
            channel_name : 'ChannelName',
            report_url : 'https://the_url_to_recieve_delivery_report.com'
        });

console.log(response);
pip install direct7
1
2
3
4
5
from direct7 import Client

client = Client(api_token="Your API token")

client.slack.send_slack_message(content="Greetings from D7 API", work_space_name="WorkspaceName", channel_name="ChannelName", report_url="https://the_url_to_recieve_delivery_report.com")

composer require direct7/direct7-php
require_once 'vendor/autoload.php';
1
2
3
4
5
6
7
8
require_once __DIR__ . '/vendor/autoload.php';

use direct7\Direct7\Client;

$client = new Client(api_token="Your API token")

$response = $direct7->slack->sendSlackMessage(content:'Hello, World!', work_space_name:'WorkSpaceName', channel_name:'ChannelName', report_url:'https://example.com/callback');
var_dump($response);
go get -u github.com/d7networks/direct7-go-sdk
import (
"github.com/d7networks/direct7-go-sdk/direct7"
)   
apiToken := "Your Api Token"
client := direct7.NewClient(apiToken)
slack := direct7.NewSlack(client)
content := "Greetings from D7 API"
workSpaceName := "WorkspaceName"
channelName := "ChannelName"
reportURL := "https://the_url_to_recieve_delivery_report.com"

response, err := slack.SendSlackMessage(content, workSpaceName, channelName, reportURL)
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n  \"message_globals\": {\n    \"report_url\": \"https://the_url_to_recieve_delivery_report.com\"\n  },\n  \"messages\": [\n    {\n      \"channel\": \"slack\",\n      \"content\": \"Greetings from D7 API\",\n      \"work_space_name\":\"WorkspaceName\",\n      \"channel_name\": \"ChannelName\"\n    }\n  ]\n}");
Request request = new Request.Builder()
.url("https://api.d7networks.com/messages/v1/send")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer {{api_access_token}}")
.build();
Response response = client.newCall(request).execute();
var headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer {{api_access_token}}'
};
var request = http.Request('POST', Uri.parse('https://api.d7networks.com/messages/v1/send'));
request.body = json.encode({
"message_globals": {
    "report_url": "https://the_url_to_recieve_delivery_report.com"
},
"messages": [
    {
    "channel": "slack",
    "content": "Greetings from D7 API",
    "work_space_name": "WorkspaceName",
    "channel_name": "ChannelName"
    }
]
});
request.headers.addAll(headers);

http.StreamedResponse response = await request.send();

if (response.statusCode == 200) {
print(await response.stream.bytesToString());
}
else {
print(response.reasonPhrase);
}
1
2
3
4
5
6
7
8
9
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("Accept", "application/json")
$headers.Add("Authorization", "Bearer {{api_access_token}}")

$body = "{`n  `"messages`": [`n    {`n        `"channel`": `"slack`",`n        `"content`": `"Greetings from D7 API`",`n    `"work_space_name`": `"WorkspaceName`",`n    `"channel_name`": `"ChannelName`",`n  }`n  ],`n  `"message_globals`": {`n    `"originator`": `"SLACK`",`n       `"report_url`": `"https://the_url_to_recieve_delivery_report.com`"`n  }`n}"

$response = Invoke-RestMethod 'https://api.d7networks.com/messages/v1/send' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
gem install direct7
1
2
3
4
5
require 'direct7'

client = Direct7::Client.new('Your API token')

client.slack.send_slack_message(content="Greetings from D7 API", work_space_name="WorkspaceName", channel_name="ChannelName", report_url="https://the_url_to_recieve_delivery_report.com")
1
2
3
4
5
6
7
8
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.d7networks.com/messages/v1/send");
request.Headers.Add("Authorization", "Bearer {{api_access_token}}");
var content = new StringContent("{\n  \"message_globals\": {\n    \"report_url\": \"https://the_url_to_recieve_delivery_report.com\"\n  },\n  \"messages\": [\n    {\n      \"channel\": \"slack\",\n      \"content\": \"Greetings from D7 API\",\n      \"work_space_name\":\"WorkspaceName\",\n      \"channel_name\": \"ChannelName\"\n    }\n  ]\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());