botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Cannot Get Azure Function Triggered.

Open Masssluis opened this issue 9 years ago • 7 comments

Hello All,

Requirement - I just want to trigger Azure Function (proactive)(Developed in visual Studio from Bot Template)similar to Proactive Template in Bot Service.

I have developed the solution directly from visual studio(without going to bot service and selecting a Proactive template).When I am testing it in emulator message gets queued but I am not able to get the trigger control back as similar to one in Proactive template.

Here is the screen shot of my azure trigger function where i have entered sender ID as bot ID.

capture56

Kindly , Let me know If i have entered wrong SenderID in the picture above.

Here is my code.

// messageRecieved method in my DialogClass

public async Task MessageRecievedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
       {
           var message = await result;
           var queueMessage = new Message()
           {
               ResumptionCookie = new ResumptionCookie(message),
               Text = message.Text   
           };

         *****---- AddMessageToQueueAsync----***** is a user defined method implementation given below.

           await AddMessageToQueueAsync(JsonConvert.SerializeObject(queueMessage));
           await context.PostAsync("Successfully queued");
           context.Wait(MessageRecievedAsync);
       }

      public static async Task AddMessageToQueueAsync(string message) {

           var storageAccount = CloudStorageAccount.Parse(Utils.GetAppSettings("AzureConfig"));

           var queueClient = storageAccount.CreateCloudQueueClient();

           var queue = queueClient.GetQueueReference("myqueue-items");

           await queue.CreateIfNotExistsAsync();
           var queueMessage = new CloudQueueMessage(message);
           await queue.AddMessageAsync(queueMessage);
        
       }

In my MessagesController.cs

// if message Type is trigger. 
`
else if (message.Type == ActivityTypes.Event)
           {    
               IEventActivity trigger =  message;
var backMessage = JsonConvert.DeserializeObject<Message(((JObject)trigger.Value).GetValue("Message").ToString());

               var messageActivity = (Activity)backMessage.ResumptionCookie.GetMessage();

               ConnectorClient client = new ConnectorClient(new Uri(messageActivity.ServiceUrl));
               var triggerReply = messageActivity.CreateReply();
               triggerReply.Text = $"This is coming back from trigger{messageActivity.Text}";
               client.Conversations.ReplyToActivityAsync(triggerReply);
             
           }

Thanks.

Masssluis avatar Jan 31 '17 07:01 Masssluis

Hey,

Since you have developed solution your self, you have to make sure that you configure application settings or environment variables containing DirectLine key, and an endpoint (was fixed in later version but since I am not sure about your version I will recommend creating one). Here is how it would look like:

Function setting

You can find this variables under your function app setting. Let me know if it still doesn't work.

maxpert avatar Jan 31 '17 17:01 maxpert

@maxpert - Thanks a lot for quick response.

I am still little confused.Please clarify me with following answers:

1.Which endpoint do i need to enter? Is it the Bot Framework messaging endpoint which is given when we publish the bot to the store? if yes, then should I provide DirectLine App secret ?

My Bot presently consists of App ID, App Secret,Bot Id in its WebConfig. so, from where can i get this Directline app secret and endpoint.

2.What must be sender ID while configuring bot message (output) in Proactive-Function , is it BotID? or anything else?

Just for information, I have developed my solution using bot builder template in Visual Studio 2015.

Its bit confusing and with no proper documentation so its hard to understand.

Thanks for your help, awaiting quick response.

Masssluis avatar Feb 01 '17 04:02 Masssluis

@msftgits @matvelloso Please help !

Masssluis avatar Feb 02 '17 06:02 Masssluis

You don't need to trigger the directline endpoint. Create a separate api with its own controller, just so you can call it from anywhere you want. In there, you start your proactive message. In fact that's exactly what I'm doing here: https://github.com/MicrosoftDX/botFramework-proactiveMessages/blob/master/csharp/simpleSendMessage/Controllers/CustomWebAPIController.cs

matvelloso avatar Feb 02 '17 16:02 matvelloso

And you might not even need the resumption cookie, take a look at the readme of that repo

matvelloso avatar Feb 02 '17 16:02 matvelloso

Hi I am using Node.js for development . I have created a bot service with proactive template . In the bot service my code is succesfully working when I send a message its added to the queue and we get trigger message after few seconds. But when i try to create the bot without using bot service in azure I am unable to figure out what will will be the messaging end point in the emulator or in bot framework . please help me .

SomaSharathSurya avatar Feb 23 '17 12:02 SomaSharathSurya

@SomaSharathSurya you can configure your endpoint via your Node server module, eg. Restify (or Express). Check out the routing docs for Restify here.

nwhitmont avatar Apr 12 '17 19:04 nwhitmont