I want to get the toneinfo of the Call class.

Yuuki Takahashi 61 Reputation points
2021-12-17T08:30:53.347+00:00

We are creating an Azure Bot that uses Teams for automatic reporting.

Currently, we have succeeded in making calls to Teams users and playing audio.

After this, we are considering having the user press a button on the dial pad to change the behavior of the bot,
but we have not been able to get a button response.

The following URL shows that the property to get is toneInfo, and I know that I need SubscribeToTone to get it.

[https://learn.microsoft.com/en-us/graph/api/resources/toneinfo?view=graph-rest-1.0]
[https://learn.microsoft.com/en-us/graph/api/call-subscribetotone?view=graph-rest-1.0&tabs=http]

        for (var i = 0; i < 120; i += 5)  
        {  
            var calls = graphServiceClient.Communications.Calls[callId];  
            if ((await calls.Request().GetAsync()).State == CallState.Established)  
            {  
                await calls  
                    .PlayPrompt(prompts)  
                    .Request()  
                    .PostAsync();  

                await calls  
                .SubscribeToTone()  
                .Request()  
                .PostAsync();  

                break;  
            }  

            Thread.Sleep(5 * 1000);  
        }  

The current code looks like this: After playing the audio with PlayPrompt, we call SubscribeToTone.

After that, I tried again to get an instance of the Call class and look at the toneInfo, but I could not get the toneInfo.
I also tried to get the toneInfo from the event of ActivityHandler, but it was not possible to get it from the event.
How can I get it?

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,154 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,715 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,886 questions
{count} votes

Accepted answer
  1. Hunaid Hanfee-MSFT 976 Reputation points
    2021-12-22T10:59:38.487+00:00

    @Yuuki Takahashi When user presses a button you will get the request at your specific callBack Url. Try to get the request that is coming. Inside the incoming request.body, you should get the property as toneInfo. Once you had it you can do toneInfo.tone to get the information.
    You will not get the toneInfo by getting call info. You need to get it from incoming request body only.

    Check the property "BodyReader" and changed the code and got the response.

    {"@odata.type":"#microsoft.graph.commsNotifications","value":[{"@odata.type":"#microsoft.graph.commsNotification","changeType":"updated","resource":"/app/calls/xxxxx","resourceUrl":"/communications/calls/xxxxxxx","resourceData":{"@odata.type":"#microsoft.graph.call","state":"established","toneInfo":{"@odata.type":"#microsoft.graph.toneInfo","sequenceId":1,"tone":"tone1"}}}]}

     ReadResult readResult = await Request.BodyReader.ReadAsync();  
     var buffer = readResult.Buffer.ToArray();  
     var doc = Encoding.UTF8.GetString(buffer);  
     var foo = doc;   
    

    Thanks,
    Hunaid Hanfee


    If the response is helpful, please click "Accept Answer" and upvote it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Yuuki Takahashi 61 Reputation points
    2021-12-22T09:57:56.913+00:00

    Thanks HunaidHanfee-MSFT.
    I reconfigured the Callback and was able to confirm that there is a response every time I press the button.
    However, I have not been able to get the toneInfo yet.
    Right now, the code looks like this This is the code in the handler called by Callback.
    The Status contains the object when the call was initiated.

                #Check toneInfo.
                var call = await Status.GraphServiceClient.Communications.Calls[Status.CallId].Request().GetAsync();
    
                #Call SubscribeToTone
                var res = await Status.GraphServiceClient.Communications.Calls[Status.CallId].SubscribeToTone()
                    .Request()
                    .PostAsync();
    
                #Check toneInfo one more time.
                call = await Status.GraphServiceClient.Communications.Calls[Status.CallId].Request().GetAsync();
    
    0 comments No comments

  2. Yuuki Takahashi 61 Reputation points
    2021-12-23T07:00:07.477+00:00

    Thanks Hunaid Hanfee.
    I have created a class for Callback as follows.
    However, the Request.Body included in the response seems to be a Stream.
    Body in the response seems to be a Stream, but when I try to read it with this code, all I get is 0.
    Is there something wrong with the way the Callback is received?

    [Route("api/callback")]
    [ApiController]
    public class CallbackController : ControllerBase
    {
        [HttpPost, HttpGet]
        public async Task Post()
        {
            if (Request.Body.CanRead)
            {
                using (var memorySt = new MemoryStream())
                {
                    await Request.Body.CopyToAsync(memorySt);
                    var result = new byte[memorySt.Length];
                    await memorySt.ReadAsync(result, 0, (int)memorySt.Length);
    
                    var doc = Encoding.UTF8.GetString(result);
    
                    var foo = doc;
                }
            }
        }
    }
    
    0 comments No comments

  3. Yuuki Takahashi 61 Reputation points
    2021-12-23T07:45:37.86+00:00

    Thanks Hunaid Hanfee.
    I noticed the property "BodyReader" and changed the code and got the response.

    {"@odata.type":"#microsoft.graph.commsNotifications","value":[{"@odata.type":"#microsoft.graph.commsNotification","changeType":"updated","resource":"/app/calls/xxxxx","resourceUrl":"/communications/calls/xxxxxxx","resourceData":{"@odata.type":"#microsoft.graph.call","state":"established","toneInfo":{"@odata.type":"#microsoft.graph.toneInfo","sequenceId":1,"tone":"tone1"}}}]}

            ReadResult readResult = await Request.BodyReader.ReadAsync();
            var buffer = readResult.Buffer.ToArray();
    
            var doc = Encoding.UTF8.GetString(buffer);
    
            var foo = doc;
    

    Thanks,
    Yuuki