Just added my bot Jessie to contacts. Now trying to start conversation and nothing is works
import requests
import requests.auth as auth
import json
url = "https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token"
headers = {'Content-Type' : 'application/x-www-form-urlencoded', 'Host' : 'login.microsoftonline.com' }
r = requests.post(url, data="grant_type=client_credentials&client_id=ID&client_secret=SECRET&scope=https%3A%2F%2Fapi.botframework.com%2F.default")
print(r.content)
jsonAuth = json.loads(r.content)
print(jsonAuth['token_type'] + ' ' + jsonAuth['access_token'])
headers2 = {'Authorization' : 'Bearer ' + jsonAuth['access_token'], 'Content-Type':'application/json' }
url = "https://smba.trafficmanager.net/apis/v3/conversations"
user = {}
user['bot'] = {}
user['bot']['id']='7444e829-f753-4f97-95c9-8c33e79087d0'
user['bot']['name']='Jessie'
user['isGroup']=False
user['members']= []
user['members'].append({'id' : 'bogdan_danson', 'name' : 'b2soft'})
user['topicName'] = 'New Alert!'
jsonRequestBody = json.dumps(user)
print(jsonRequestBody)
req = requests.post(url, headers=headers2, data=jsonRequestBody)
print(req.content)
And I get response:
b'{"error":{"code":"BadSyntax","message":"Bad format of conversation ID"}}'
What am I doing wrong? Do I need other flow or user ID? Bot has not yet published, just tried to test it.
I want to start conversation with user and then read/answer in chat or group with users
It is not clear how you have got the id. As far as I can see, it seems you are apparently using the explicit Skype id (bogdan_danson) of the user in place of
user['members'][0]['id']
but I think that's not the id you are supposed to use.When a webhook is fixed and when a person sends a message to your bot, then a json of this kind will be played:
Now,
user['members'][0]['id']
should equal to the<chat id>
of the user, instead of his/her explicit Skype id.To get
<chat id>
of a new user from a group:If your bot was added to a group, a json object of this kind must have been received to your webhook:
From this, you can get of the conversation and the chat ids of members of the group right at the instant of time the bot was added to the group.
To get the updated members (chat ids and names), as per API reference, you can do something like this:
And you will receive a response like this:
You can get the chat id of members from this.
Now, you can proceed with requesting for id in order to start a conversation.
To start a conversation with a member, after having known the chat id and name of the member, you are supposed to run something like this:
You may then receive something like this:
Note: In sending a personal message,
<conversation id>
happens to be the same as<chat id>
.Once you receive
<new id>
, you can use something like this to finally send a message to the conversation: