How to set `You and moderator can reply` in bot when posting proactive message to channels?

Viewed 106

I am currently developing a bot that posts proactive message to channels. My client wants me to set No reply or You and moderator can reply on the message that posted from the bot proactively. 

What I tried so far:

// post message to channels
const credentials = new MicrosoftAppCredentials(process.env.MicrosoftAppId, process.env.MicrosoftAppPassword);
const client = new ConnectorClient(credentials, { baseUri: serviceUrl });
const message = MessageFactory.text(inMessage);

let approveResult = false;
let MessageActivityId = "";

const conversationParams = {
    isGroup: true,
    bot: {
        id: process.env.MicrosoftAppId,
        name: process.env.BotName
    },
    conversationType: 'channel',
    channelData: {
        channel: {
            id: teamsChannelId
        }
    },
    activity: message
};

const msRes = await client.conversations.createConversation(conversationParams).catch(e => console.log(e));

I tried to post the message first, and immediately update the activity and set the type as ActivityTypes.EndOfConversation. However, it doesn't work at all.

const tmpResult = await client.conversations.updateActivity(teamsChannelId, msRes.activityId, {type: ActivityTypes.EndOfConversation})

Error form above updateActivity code: 

RestError: Unknown activity type
at ...(skipped for paths)

{
    code: 'BadArgument',
    statusCode: 400,
    request: WebResource {
        streamResponseBody: false,
        url: 'https://{service_url}/{channel_id}/activities/{messageActivityId}',
        method: 'PUT',
        headers: HttpHeaders {
            _headersMap: [Object]
        },
        body: '{"type":"endOfConversation"}',
        query: undefined,
        formData: undefined,
        withCredentials: false,
        abortSignal: undefined,
        timeout: 0,
        onUploadProgress: undefined,
        onDownloadProgress: undefined,
        proxySettings: undefined,
        keepAlive: undefined,
        agentSettings: undefined,
        operationSpec: {
            httpMethod: 'PUT',
            path: 'v3/conversations/{conversationId}/activities/{activityId}',
            urlParameters: [Array],
            requestBody: [Object],
            responses: [Object],
            serializer: [Serializer]
        }
    },
    response: {
        body: '{"error":{"code":"BadArgument","message":"Unknown activity type"}}',
        headers: HttpHeaders {
            _headersMap: [Object]
        },
        status: 400
    },
    body: {
        error: {
            code: 'BadArgument',
            message: 'Unknown activity type'
        }
    }
}

Is there any method that allows me to do so? Thanks. It would be better if I could only disable the reply function in Channels from bot programmatically.


Update on 2021-06-28:

Simulation of expected behavior on UI: enter image description here

Simulation of actual behavior on UI: enter image description here

1 Answers
Related