Maxim V. Pavlov
Maxim V. Pavlov

Reputation: 10509

How to enable bot to find Skype group chat it was added to previously?

I am creating a bot with Microsoft Bot Framework that is supposed to, when receives notification from CI server, notify about build events participants of a particular chat group in Skype.

I don't quite get it, when I've added Skype bot to the chat, it has received an activity that presumably would have allowed me to save some Id at that stage. But since I need the bot to be proactive and post messages based on external stimuli, I would need to know the reference to that group chat permanently, including after re-deployment. But after redeployments, I don't have a conversation reference.

In theory, what bit of data, given that I save it during add time, would enable me to proactively send messages at any given point in time?

Upvotes: 0

Views: 136

Answers (1)

rudolf_franek
rudolf_franek

Reputation: 1885

If it is ok that all participants "join" the conversation by writing first to the bot and if your bot accepts messages in similar Post method

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
    string rawActivity = JsonConvert.SerializeObject(activity);
    Save(rawActivity);
}

Then you are able to send messages to that conversation from your bot any time by using following code. You can restart or even redeploy your bot in the meantime. I have tested about one week as maximum time between consecutive messages.

public void MethodInvokedByExternalEvent(string externalMessage)
{
    var activity = JsonConvert.DeserializeObject<Activity>(GetStoredActivity());
    var replyActivity = activity.CreateReply(externalMessage);

    ResourceResponse reply = null;
    using (var client = new ConnectorClient(new Uri(activity.ServiceUrl)))
    {
        reply = client.Conversations.ReplyToActivity(replyActivity);
    }
}

Upvotes: 2

Related Questions