Skip to main content
Get the temporary download link for a file in a bot message.

API call description

  1. When a user sends an image, voice, video, file, or rich text message to the bot, obtain the temporary download code downloadCode from the information that the bot returns to the developer through the callback.
  2. Use the temporary download code downloadCode to call this API and obtain the temporary download link for the image, voice, file, or video in the message.
  3. Access the temporary download link to retrieve the file content.

Description

  • In a group chat: When a group member @s the bot, the bot does not support receiving voice, file, or video messages.
  • In a one-to-one chat between users: The bot does not support receiving voice, file, or video messages.
  • In a one-to-one chat between a user and a bot: The bot supports receiving voice, file, and video messages.

Request

Basic information

FieldValue
HTTP URLhttps://api.dingtalk.io/v1.0/robot/messageFiles/download
HTTP MethodPOST
Supported app typesappType-Internal app appType-Third-party enterprise app
Required permissionpermission-qyapi_robot_sendmsg-Permission to send messages from a bot in your organization

Request header

NameTypeRequiredDescription
x-acs-dingtalk-access-tokenStringYesThe access credential for calling this API. Obtain it as follows: - For an internal app, call the Obtain the access token of an internal app API. - For a third-party enterprise app, call the Obtain the access token of an enterprise authorized by a third-party app API.

Request body

NameTypeRequiredDescription
downloadCodeStringYesThe download code returned by the bot to the developer after a user sends a file message to the bot. For more information, see Bot receives messages.
robotCodeStringYesThe code of the bot. For more information, see Bot ID.

Request example

HTTP
POST /v1.0/robot/messageFiles/download HTTP/1.1
Host:api.dingtalk.io
x-acs-dingtalk-access-token:qkops*****cviojsdjn
Content-Type:application/json

{
  "downloadCode" : "mIofN*********gn38tqVwL+zoRgzXipAMzmV5uhVKUlBdjKugAIvsm+TrvaPI0JYCMjvFMAlXvMWnMJsi2nZ9a0+N2c9CoV90hiB/B+fEThASPz+jmIa4J6x4WTsmmU3E/AopGsSGugE+hkHBcu52o76Yd2SCpPNUqenvdySSqjowEt1+Ddz55/9Qj8Y8ZhTryqsb7tYwzLFB+F3lsWCotXBOQvEgy3e/bEQtOyV6YrP3KG6YNSb3Q==",
  "robotCode" : "ding******yn0pjqd"
}
Java
// This file is auto-generated, don't edit it. Thanks.
package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * Initialize the account Client using a Token
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dingtalkrobot_1_0.Client createClient() throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
        config.protocol = "https";
        config.regionId = "central";
        return new com.aliyun.dingtalkrobot_1_0.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.dingtalkrobot_1_0.Client client = Sample.createClient();
        com.aliyun.dingtalkrobot_1_0.models.RobotMessageFileDownloadHeaders robotMessageFileDownloadHeaders = new com.aliyun.dingtalkrobot_1_0.models.RobotMessageFileDownloadHeaders();
        robotMessageFileDownloadHeaders.xAcsDingtalkAccessToken = "<your access token>";
        com.aliyun.dingtalkrobot_1_0.models.RobotMessageFileDownloadRequest robotMessageFileDownloadRequest = new com.aliyun.dingtalkrobot_1_0.models.RobotMessageFileDownloadRequest()
                .setDownloadCode("mIofN*********gn38tqVwL+zoRgzXipAMzmV5uhVKUlBdjKugAIvsm+TrvaPI0JYCMjvFMAlXvMWnMJsi2nZ9a0+N2c9CoV90hiB/B+fEThASPz+jmIa4J6x4WTsmmU3E/AopGsSGugE+hkHBcu52o76Yd2SCpPNUqenvdySSqjowEt1+Ddz55/9Qj8Y8ZhTryqsb7tYwzLFB+F3lsWCotXBOQvEgy3e/bEQtOyV6YrP3KG6YNSb3Q==")
                .setRobotCode("ding******yn0pjqd");
        try {
            client.robotMessageFileDownloadWithOptions(robotMessageFileDownloadRequest, robotMessageFileDownloadHeaders, new com.aliyun.teautil.models.RuntimeOptions());
        } catch (TeaException err) {
            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
                // The err contains code and message attributes, which help locate the issue
            }

        } catch (Exception _err) {
            TeaException err = new TeaException(_err.getMessage(), _err);
            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
                // The err contains code and message attributes, which help locate the issue
            }

        }        
    }
}
Python
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys

from typing import List

from alibabacloud_dingtalk.robot_1_0.client import Client as dingtalkrobot_1_0Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_dingtalk.robot_1_0 import models as dingtalkrobot__1__0_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient

class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client() -> dingtalkrobot_1_0Client:
        """
        Initialize the account Client using a Token
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config()
        config.protocol = 'https'
        config.region_id = 'central'
        return dingtalkrobot_1_0Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        robot_message_file_download_headers = dingtalkrobot__1__0_models.RobotMessageFileDownloadHeaders()
        robot_message_file_download_headers.x_acs_dingtalk_access_token = '<your access token>'
        robot_message_file_download_request = dingtalkrobot__1__0_models.RobotMessageFileDownloadRequest(
            download_code='mIofN*********gn38tqVwL+zoRgzXipAMzmV5uhVKUlBdjKugAIvsm+TrvaPI0JYCMjvFMAlXvMWnMJsi2nZ9a0+N2c9CoV90hiB/B+fEThASPz+jmIa4J6x4WTsmmU3E/AopGsSGugE+hkHBcu52o76Yd2SCpPNUqenvdySSqjowEt1+Ddz55/9Qj8Y8ZhTryqsb7tYwzLFB+F3lsWCotXBOQvEgy3e/bEQtOyV6YrP3KG6YNSb3Q==',
            robot_code='ding******yn0pjqd'
        )
        try:
            client.robot_message_file_download_with_options(robot_message_file_download_request, robot_message_file_download_headers, util_models.RuntimeOptions())
        except Exception as err:
            if not UtilClient.empty(err.code) and not UtilClient.empty(err.message):
                # The err contains code and message attributes, which help locate the issue
                pass

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        robot_message_file_download_headers = dingtalkrobot__1__0_models.RobotMessageFileDownloadHeaders()
        robot_message_file_download_headers.x_acs_dingtalk_access_token = '<your access token>'
        robot_message_file_download_request = dingtalkrobot__1__0_models.RobotMessageFileDownloadRequest(
            download_code='mIofN*********gn38tqVwL+zoRgzXipAMzmV5uhVKUlBdjKugAIvsm+TrvaPI0JYCMjvFMAlXvMWnMJsi2nZ9a0+N2c9CoV90hiB/B+fEThASPz+jmIa4J6x4WTsmmU3E/AopGsSGugE+hkHBcu52o76Yd2SCpPNUqenvdySSqjowEt1+Ddz55/9Qj8Y8ZhTryqsb7tYwzLFB+F3lsWCotXBOQvEgy3e/bEQtOyV6YrP3KG6YNSb3Q==',
            robot_code='ding******yn0pjqd'
        )
        try:
            await client.robot_message_file_download_with_options_async(robot_message_file_download_request, robot_message_file_download_headers, util_models.RuntimeOptions())
        except Exception as err:
            if not UtilClient.empty(err.code) and not UtilClient.empty(err.message):
                # The err contains code and message attributes, which help locate the issue
                pass

if __name__ == '__main__':
    Sample.main(sys.argv[1:])
PHP
<?php

// This file is auto-generated, don't edit it. Thanks.
namespace AlibabaCloud\SDK\Sample;

use AlibabaCloud\SDK\Dingtalk\Vrobot_1_0\Dingtalk;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dingtalk\Vrobot_1_0\Models\RobotMessageFileDownloadHeaders;
use AlibabaCloud\SDK\Dingtalk\Vrobot_1_0\Models\RobotMessageFileDownloadRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

class Sample {

    /**
     * Initialize the account Client using a Token
     * @return Dingtalk Client
     */
    public static function createClient(){
        $config = new Config([]);
        $config->protocol = "https";
        $config->regionId = "central";
        return new Dingtalk($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient();
        $robotMessageFileDownloadHeaders = new RobotMessageFileDownloadHeaders([]);
        $robotMessageFileDownloadHeaders->xAcsDingtalkAccessToken = "<your access token>";
        $robotMessageFileDownloadRequest = new RobotMessageFileDownloadRequest([
            "downloadCode" => "mIofN*********gn38tqVwL+zoRgzXipAMzmV5uhVKUlBdjKugAIvsm+TrvaPI0JYCMjvFMAlXvMWnMJsi2nZ9a0+N2c9CoV90hiB/B+fEThASPz+jmIa4J6x4WTsmmU3E/AopGsSGugE+hkHBcu52o76Yd2SCpPNUqenvdySSqjowEt1+Ddz55/9Qj8Y8ZhTryqsb7tYwzLFB+F3lsWCotXBOQvEgy3e/bEQtOyV6YrP3KG6YNSb3Q==",
            "robotCode" => "ding******yn0pjqd"
        ]);
        try {
            $client->robotMessageFileDownloadWithOptions($robotMessageFileDownloadRequest, $robotMessageFileDownloadHeaders, new RuntimeOptions([]));
        }
        catch (Exception $err) {
            if (!($err instanceof TeaError)) {
                $err = new TeaError([], $err->getMessage(), $err->getCode(), $err);
            }
            if (!Utils::empty_($err->code) && !Utils::empty_($err->message)) {
                // The err contains code and message attributes, which help locate the issue
            }
        }
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
Sample::main(array_slice($argv, 1));
Go
// This file is auto-generated, don't edit it. Thanks.
package main

import (
  "os"
  util  "github.com/alibabacloud-go/tea-utils/v2/service"
  dingtalkrobot_1_0  "github.com/alibabacloud-go/dingtalk/robot_1_0"
  openapi  "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  "github.com/alibabacloud-go/tea/tea"
)

/**
 * Initialize the account Client using a Token
 * @return Client
 * @throws Exception
 */
func CreateClient () (_result *dingtalkrobot_1_0.Client, _err error) {
  config := &openapi.Config{}
  config.Protocol = tea.String("https")
  config.RegionId = tea.String("central")
  _result = &dingtalkrobot_1_0.Client{}
  _result, _err = dingtalkrobot_1_0.NewClient(config)
  return _result, _err
}

func _main (args []*string) (_err error) {
  client, _err := CreateClient()
  if _err != nil {
    return _err
  }

  robotMessageFileDownloadHeaders := &dingtalkrobot_1_0.RobotMessageFileDownloadHeaders{}
  robotMessageFileDownloadHeaders.XAcsDingtalkAccessToken = tea.String("<your access token>")
  robotMessageFileDownloadRequest := &dingtalkrobot_1_0.RobotMessageFileDownloadRequest{
    DownloadCode: tea.String("mIofN*********gn38tqVwL+zoRgzXipAMzmV5uhVKUlBdjKugAIvsm+TrvaPI0JYCMjvFMAlXvMWnMJsi2nZ9a0+N2c9CoV90hiB/B+fEThASPz+jmIa4J6x4WTsmmU3E/AopGsSGugE+hkHBcu52o76Yd2SCpPNUqenvdySSqjowEt1+Ddz55/9Qj8Y8ZhTryqsb7tYwzLFB+F3lsWCotXBOQvEgy3e/bEQtOyV6YrP3KG6YNSb3Q=="),
    RobotCode: tea.String("ding******yn0pjqd"),
  }
  tryErr := func()(_e error) {
    defer func() {
      if r := tea.Recover(recover()); r != nil {
        _e = r
      }
    }()
    _, _err = client.RobotMessageFileDownloadWithOptions(robotMessageFileDownloadRequest, robotMessageFileDownloadHeaders, &util.RuntimeOptions{})
    if _err != nil {
      return _err
    }

    return nil
  }()

  if tryErr != nil {
    var err = &tea.SDKError{}
    if _t, ok := tryErr.(*tea.SDKError); ok {
      err = _t
    } else {
      err.Message = tea.String(tryErr.Error())
    }
    if !tea.BoolValue(util.Empty(err.Code)) && !tea.BoolValue(util.Empty(err.Message)) {
      // The err contains code and message attributes, which help locate the issue
    }

  }
  return _err
}

func main() {
  err := _main(tea.StringSlice(os.Args[1:]))
  if err != nil {
    panic(err)
  }
}
Node.js
// This file is auto-generated, don't edit it
import Util, * as $Util from '@alicloud/tea-util';
import dingtalkrobot_1_0, * as $dingtalkrobot_1_0 from '@alicloud/dingtalk/robot_1_0';
import OpenApi, * as $OpenApi from '@alicloud/openapi-client';
import * as $tea from '@alicloud/tea-typescript';

export default class Client {

  /**
   * Initialize the account Client using a Token
   * @return Client
   * @throws Exception
   */
  static createClient(): dingtalkrobot_1_0 {
    let config = new $OpenApi.Config({ });
    config.protocol = "https";
    config.regionId = "central";
    return new dingtalkrobot_1_0(config);
  }

  static async main(args: string[]): Promise<void> {
    let client = Client.createClient();
    let robotMessageFileDownloadHeaders = new $dingtalkrobot_1_0.RobotMessageFileDownloadHeaders({ });
    robotMessageFileDownloadHeaders.xAcsDingtalkAccessToken = "<your access token>";
    let robotMessageFileDownloadRequest = new $dingtalkrobot_1_0.RobotMessageFileDownloadRequest({
      downloadCode: "mIofN*********gn38tqVwL+zoRgzXipAMzmV5uhVKUlBdjKugAIvsm+TrvaPI0JYCMjvFMAlXvMWnMJsi2nZ9a0+N2c9CoV90hiB/B+fEThASPz+jmIa4J6x4WTsmmU3E/AopGsSGugE+hkHBcu52o76Yd2SCpPNUqenvdySSqjowEt1+Ddz55/9Qj8Y8ZhTryqsb7tYwzLFB+F3lsWCotXBOQvEgy3e/bEQtOyV6YrP3KG6YNSb3Q==",
      robotCode: "ding******yn0pjqd",
    });
    try {
      await client.robotMessageFileDownloadWithOptions(robotMessageFileDownloadRequest, robotMessageFileDownloadHeaders, new $Util.RuntimeOptions({ }));
    } catch (err) {
      if (!Util.empty(err.code) && !Util.empty(err.message)) {
        // The err contains code and message attributes, which help locate the issue
      }

    }    
  }

}

Client.main(process.argv.slice(2));
C#
// This file is auto-generated, don't edit it. Thanks.

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

using Tea;
using Tea.Utils;

namespace AlibabaCloud.SDK.Sample
{
    public class Sample 
    {

        /**
         * Initialize the account Client using a Token
         * @return Client
         * @throws Exception
         */
        public static AlibabaCloud.SDK.Dingtalkrobot_1_0.Client CreateClient()
        {
            AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config();
            config.Protocol = "https";
            config.RegionId = "central";
            return new AlibabaCloud.SDK.Dingtalkrobot_1_0.Client(config);
        }

        public static void Main(string[] args)
        {
            AlibabaCloud.SDK.Dingtalkrobot_1_0.Client client = CreateClient();
            AlibabaCloud.SDK.Dingtalkrobot_1_0.Models.RobotMessageFileDownloadHeaders robotMessageFileDownloadHeaders = new AlibabaCloud.SDK.Dingtalkrobot_1_0.Models.RobotMessageFileDownloadHeaders();
            robotMessageFileDownloadHeaders.XAcsDingtalkAccessToken = "<your access token>";
            AlibabaCloud.SDK.Dingtalkrobot_1_0.Models.RobotMessageFileDownloadRequest robotMessageFileDownloadRequest = new AlibabaCloud.SDK.Dingtalkrobot_1_0.Models.RobotMessageFileDownloadRequest
            {
                DownloadCode = "mIofN*********gn38tqVwL+zoRgzXipAMzmV5uhVKUlBdjKugAIvsm+TrvaPI0JYCMjvFMAlXvMWnMJsi2nZ9a0+N2c9CoV90hiB/B+fEThASPz+jmIa4J6x4WTsmmU3E/AopGsSGugE+hkHBcu52o76Yd2SCpPNUqenvdySSqjowEt1+Ddz55/9Qj8Y8ZhTryqsb7tYwzLFB+F3lsWCotXBOQvEgy3e/bEQtOyV6YrP3KG6YNSb3Q==",
                RobotCode = "ding******yn0pjqd",
            };
            try
            {
                client.RobotMessageFileDownloadWithOptions(robotMessageFileDownloadRequest, robotMessageFileDownloadHeaders, new AlibabaCloud.TeaUtil.Models.RuntimeOptions());
            }
            catch (TeaException err)
            {
                if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
                {
                    // The err contains code and message attributes, which help locate the issue
                }
            }
            catch (Exception _err)
            {
                TeaException err = new TeaException(new Dictionary<string, object>
                {
                    { "message", _err.Message }
                });
                if (!AlibabaCloud.TeaUtil.Common.Empty(err.Code) && !AlibabaCloud.TeaUtil.Common.Empty(err.Message))
                {
                    // The err contains code and message attributes, which help locate the issue
                }
            }
        }

    }
}

Response

Response body

NameTypeDescription
downloadUrlStringThe temporary download link for the file. Access the temporary download link to retrieve the file. After the file is downloaded locally, the developer must replace the local file extension. For example, to replace a video file extension: - Before: iAEI******IVAiYgXNCKMGzSsRB85j_Z7zCM0CYA.file. - After: iAEI******IVAiYgXNCKMGzSsRB85j_Z7zCM0CYA.mp4.

Response body example

HTTP/1.1 200 OK
Content-Type:application/json

{
  "downloadUrl" : "http://wukong-**********gEv&Signature=5BNf2tBJcpKpkQw4wakBBM6ZJ0E%3D&Expires=1671377946"
}

Error codes

If an error occurs when you call this API, look up the solution in the Global error codes document based on the error message.
HttpCodeError codeError messageDescription
400invalidParameter.robotCode.emptyThe bot robotCode is empty.The bot robotCode is invalid. Check whether the bot is in the group.
400invalidParameter.robotCode.authThis downloadCode does not match the bot robotCode. Use the robotCode of the bot that received this message and the corresponding downloadCode.This downloadCode does not match the bot robotCode. Use the robotCode of the bot that received this message and the corresponding downloadCode.
400invalidParameter.robotCode.emptyThe bot downloadCode is empty.The bot downloadCode is empty.
400invalidParameter.robotCode.authThis API can only be called by an internal app or an authorized third-party app.This API can only be called by an internal app or an authorized third-party app.
400invalidParameter.robotCode.downloadCodeThe download code is incorrect or has expired.The download code is incorrect or has expired.
400invalidParameter.robotCode.authThe organization that calls this API is different from the organization to which the bot corresponding to this downloadCode belongs.The organization that calls this API is different from the organization to which the bot corresponding to this downloadCode belongs.