I'm creating a bot using REST API. Indeed, I want to send a message from my bot to me as following
I start with 'Authentification'
Request:
curl -k -X POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token -d "grant_type=client_credentials&client_id={app_id}&client_secret={app_password}&scope=https://graph.microsoft.com/.default"
Response:
{
"token_type": "Bearer",
"expires_in": 3599,
"ext_expires_in": 0,
"access_token": "<access_token>"
}
Next, I start a new conversation
Request:
POST https://skype.botframework.com/v3/conversations
Authorization: Bearer <access_token>
Content-Type: application/json
{
"bot": {
"id": "standupalice",
"name": "Standup Alice"
},
"isGroup": false,
"members": [
{
"id": "<my bot id>",
"name": "Standup Alice"
},
{
"id": "<my user id>",
"name": "Bao"
}
],
"topicName": "News Alert"
}
NOTE: and are obtained from a callback message sent from Skype app to Standup Alice bot.
Response:
{
"id": "<conversation id>"
}
It's weird since the conversation ID is identical to . Well, now I compose a message to send to me as following
Request:
POST https://skype.botframework.com/v3/conversations/<conversation id>/activities
Authorization: Bearer <access_token>
Content-Type: application/json
{
"type": "message",
"from": {
"id": "<my bot id>",
"name": "Standup Alice"
},
"conversation": {
"id": "<conversation id>",
"name": "News Alert"
},
"recipient": {
"id": "<my user id>",
"name": "Bao"
},
"channelId": "skype",
"text": "My bot's reply"
}
Response (http error 400 - bad request):
{
"error": {
"code": "ServiceError",
"message": "The conversationId <conversation id>and bot <my bot id> doesn't match a known conversation"
}
}
Do you have an idea what's wrong with my requests and parameters?
Note 1: I tried to fire request to https://api.botframework.com/v3/conversations as described in https://docs.botframework.com/en-us/core-concepts/overview/#navtitle, but always receives http error 404 - Resource not found.
Note 2: I just tried the same way for webchat and it works fine, but MS Teams doesn't work (http error 500 - Internal Server Error)
Note 3: my channel settings
Your second API request (the one starting a conversation) should have returned something looking like this:
{
"activityId": "string",
"serviceUrl": "string",
"id": "string"
}
The fact that it didn't suggests to me that that's where the problem is (although full disclosure, I wasn't able to re-create it).
Looking at your "members" array, I see you added the bot. I'm not sure, strictly speaking, that a bot is a member (I think members are human, but I can't find a good definition). So, my best suggestion would be to remove the bot from the members array in that second API call.
Good luck!
Related
I'm trying to sendConversation History API provided by Microsoft in BotFramework Documentation. It takes Transcript object (array of activities) as the input. But I've getting HTTP 400 Bad Request when using trying that.
I'm making a POST request on this and authenticating it using JWT Token generated by client credentials for the bot.
https://directline.botframework.com/v3/conversations/HBoZPkTiBYOAadigqEqFaJ-us/activities/history
This is the error I get.
{
"error": {
"code": "BadSyntax",
"message": "Invalid or missing activities"
}
}
This is the activity array payload that I'm using
[
{
"type": "message",
"id": "HBoZPkTiBYOAadigqEqFaJ-us|0000003",
"timestamp": "2022-09-05T08:10:00.3574378Z",
"localTimestamp": "2022-09-05T13:39:57.633+05:30",
"localTimezone": "Asia/Calcutta",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "dl_uID1",
"name": "userName"
},
"conversation": {
"id": "HBoZPkTiBYOAadigqEqFaJ-us"
},
"recipient": {
"id": "bot-name-dev#abcd",
"name": "bot-name-dev"
},
"textFormat": "plain",
"locale": "en-GB",
"text": "hi",
"channelData": {
"clientActivityID": "1662365337633rmq6e8mbm09",
"clientTimestamp": "2022-09-05T08:09:57.633Z"
}
}
]
I'm not able to figure out what's the correct format of activity object that it is expecting.
Create the bot and get it connected to the Direct Line. Get the secret keys of the site that need to connect.
Before calling SendConversationHistory if the message is delivered to the recipient, it will create the bad request error message as it is unable to get the conversation history as the message was already received. SendConversationHistory must be called before sending the message then the Conversation History will be tracked. The below screens will be helpful to create the DirectLine connection to the bot created. Then needed to add the trusted sites to DirectLine. Then proceed with the code sample mentioned below which takes the conversation history.
Click on Create a resource
Search for bot and click on create
Select Channels
Get the App Service Extension Keys and click on Default_site
Click on the toggle and enable the enhanced authentication options and add the website which we need to communicate.
In the code block of the current working application, to get the conversation history, use the following code block.
foreach (var a in activities)
{
incrementId++;
// Use your own ID format
a.Id = string.Concat("history|", incrementId.ToString().PadLeft(7, '0'));
a.ChannelData = null;
a.Conversation = new ConversationAccount(id: convId);
if (a.From.Name == message.Recipient.Name)
{
// Bot to recipient connection
a.Recipient = message.From;
a.From = message.Recipient;
}
else
{
// User to bot connection (here bot will be the recipient)
a.Recipient = message.Recipient;
a.From = message.From;
}
}
After connecting with Microsoft, I found this is the correct payload for this API.
{
"activities": [
{
"type": "message",
"id": "whatever-conversation-id-in|0000000",
"timestamp": "2022-11-20T20:14:26.242902Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "dl_test_id",
"name": ""
},
"conversation": {
"id": "whatever-conversation-id-in"
},
"recipient": {
"id": "ABC_bot",
"name": "ABC_bot"
},
"text": "Hello Bot"
}
]
}
Ok. So let me try to set the stage here.
I have a Microsoft Teams Application that has a Bot (Bot Framework v4) associated with it.
I have a use case where when a specific type of compliance activity happens, I need my bot to join the scheduled meeting and participate.
I am able to send a meeting invitation to an email account associated with the bot, and the bot accepts the invite.
According to this documentation, I should be able to join the meeting in progress.
(https://learn.microsoft.com/en-us/graph/api/application-post-calls?view=graph-rest-1.0&tabs=http) - Specifically "Example 5"
According to what I am reading, once you have the required Graph Permissions on your App Id that's associated, you only need 3 pieces of information to join the call (Passed in through a communications/call/create).
Post to https://graph.microsoft.com/v1.0/communications/calls :
Body:
{
"#odata.type": "#microsoft.graph.call",
"callbackUri": "https://bot.contoso.com/callback",
"requestedModalities": [
"audio"
],
"mediaConfig": {
"#odata.type": "#microsoft.graph.serviceHostedMediaConfig",
"preFetchMedia": []
},
"chatInfo": {
"#odata.type": "#microsoft.graph.chatInfo",
"threadId": "19:meeting_XXXXXXXXXXXXXXXX#thread.v2",
"messageId": "0"
},
"meetingInfo": {
"#odata.type": "#microsoft.graph.organizerMeetingInfo",
"organizer": {
"#odata.type": "#microsoft.graph.identitySet",
"user": {
"#odata.type": "#microsoft.graph.identity",
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"tenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"displayName": "Drew Jenkel"
}
},
"tenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"allowConversationWithoutHost": true
}
}
Upon doing this, I'm getting a 403 / Forbidden:
{
"error": {
"code": "7505",
"message": "Request authorization tenant mismatch.",
"innerError": {
"request-id": "30739bd2-37b2-4bfc-9c52-36d72a4aa54e",
"date": "2020-06-08T16:47:36"
}
}
}
Has anyone seen anything this this?
We set up a new Microsoft Teams Connector and successfully set the settings to POST cards to the received WebhookUrl.
In the body that we send, we included the option to make HttpPost requests to a defined target URL (using ngrok.io tunnel for development). You can see the sent messageCard below:
{
"#type": "MessageCard",
"#context": "https://schema.org/extensions",
"summary": "Card \"Test card\"",
"themeColor": "0078D7",
"title": "Card created: \"Just another test\"",
"potentialAction": [
{
"#type": "ActionCard",
"name": "Add a comment",
"inputs": [
{
"#type": "TextInput",
"id": "comment",
"isMultiline": true,
"title": "Enter your comment"
}
],
"actions": [
{
"#type": "HttpPOST",
"name": "Ok",
"target": "https://dd846f80.ngrok.io/teamshooks/actions",
"body": "{\"Comment\":\"This is a test\"}",
"headers": [
{
"Content-Type": "application/json"
},
{
"aw-teamid": "00000000-0000-0000-0000-000000000001"
}
]
}
]
}
]
}
The card is displayed correctly in the channel in Microsoft Teams.
When a user clicks on this button, to make a HttpPOST to the specified url, we never receive the request on our side but can see that Microsoft returns the following response to the internal "executeAction" request:
The request was sent on: Fri, 13 Dec 2019 11:09:48 GMT
{
"status": "Failed",
"actionId": "c520b20a-3e04-4e21-b4fd-c3a2f760c533",
"properties":
{
"displayMessage": "<p>Could not complete the requested action. Please try again later.</p>\n",
"errorCode": "ODataContentTypeException"
}
}
The following settings are set-up in the Connectors Developer Dashboard (and in the manifest.json):
"connectors": [
{
"connectorId": "6b2ba9c0-7c0a-4524-9e6d-64f061350aa4",
"scopes": [
"team"
],
"configurationUrl": "https://dd846f80.ngrok.io/msteams/aworkConnector/config.html"
}
]
"validDomains": [
"dd846f80.ngrok.io"
]
Do you want to enable actions on your Connector cards? - Yes
Actions Url: https://dd846f80.ngrok.io/teamshooks/actions
Is there anything we are currently doing wrong or does anyone have an idea on how to solve the returned ODataContentTypeException? We need to receive the request in our backend, in order to integrate Micorsoft Teams into our software.
Upload the manifest.json from an admin account, and add the ngrok url in the valid domains. Microsoft teams have blocked custom connectors from performing actions when uploaded by non admin users
How to Add a subscription for the authenticated user's channel
https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&key={YOUR_API_KEY}
Request Parameters :-
{
"0":
{ "name": " <code>snippet.resourceId.kind</code>", "value": "youtube#channel" },
"1": { "name": " <code>snippet.resourceId.channelId</code>", "value": "UC_x5XG1OV2P6uZZ5FSM9Ttw" }
}
Response Parameters :-
{
"error":
{ "errors":
[ { "domain": "youtube.subscription", "reason": "publisherRequired", "message": "The subscription resource specified in the request must use the <code>snippet.resourceId</code> property to identify the channel that is being subscribed to." } ], "code": 400, "message": "The subscription resource specified in the request must use the <code>snippet.resourceId</code> property to identify the channel that is being subscribed to." }
}
This apears to be a bug in the Youtube api. this can be verifyed by checking the api explorer here .
POST https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&key={YOUR_API_KEY}
{
"0": {
"name": "snippet.resourceId",
"value": "youtube#channel"
},
"1": {
"name": "snippet.resourceId",
"value": "UC_x5XG1OV2P6uZZ5FSM9Ttw"
}
}
Response
{
"error": {
"errors": [
{
"domain": "youtube.subscription",
"reason": "publisherRequired",
"message": "The subscription resource specified in the request must use the <code>snippet.resourceId</code> property to identify the channel that is being subscribed to."
}
],
"code": 400,
"message": "The subscription resource specified in the request must use the <code>snippet.resourceId</code> property to identify the channel that is being subscribed to."
}
}
There is an issue request for this issue and the team has been pinged.
Link of Youtube Data API (V3), you can try here
it's the image example in "try this API" of how i do
POST https://www.googleapis.com/youtube/v3/subscriptions?part=snippet HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json
{
"snippet": {
"resourceId": {
"kind": "youtube#channel",
"channelId": "UCUK0HBIBWgM2c4vsPhkYY4w"
}
}
}
When I post a message to my Microsoft bot using Postman, the message is sent to my Skype. When I post the message to Telegram channel, I get error message 400 Bad Request (The request cannot be fulfilled due to bad syntax. The following is post body.
{
"type": "message",
"locale": "en-Us",
"channelID":"telegram",
"from": {
"id": "28:01a4752e-6cb0-459f-b94f-.....",
"name": "bot"
},
"recipient": {
"id": "29:1rNJPaNGCMPithEDVjoN00SU5S6fG......",
"name": "My name"
},
"conversation": {
"id": "29:1rNJPaNGCMPithEDVjoN00SU5S6fGZ"
},
"channelData":
{
"method": "sendMessage",
"parameters":
{
"text": "This message is HTMLformatted.",
"parse_mode": "HTML"
}
}
}