A project I am currently working on involves creating a bot that sends proactive messages to channels. The client has requested that I include options like No reply
or You and moderator can reply
with the messages posted by the bot proactively.
Here is what I have attempted so far:
// posting 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 initially tried posting the message and then updating the activity immediately with the type set as ActivityTypes.EndOfConversation
. However, this approach did not yield the desired results.
const tmpResult = await client.conversations.updateActivity(teamsChannelId, msRes.activityId, {type: ActivityTypes.EndOfConversation})
Error encountered while using the updateActivity code above:
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 a different method available to achieve this goal? Any guidance would be greatly appreciated. It would be ideal if I could programmatically disable the reply function in Channels from the bot.
Update on 2021-06-28:
Expected Behavior Simulation: https://i.sstatic.net/2gTTb.png
Actual Behavior Simulation: https://i.sstatic.net/EnTM2.png