c# - ConversationUpdate doesn't trigger after publish -


hi created first test bot using microsoft botframework in c#. in private async task< activity > handlesystemmessage(activity message) in if (message.type == activitytypes.conversationupdate) should notify new member added group or hit start button of bot in telegram messenger. when test in debug mode using botframework emulator works after publish see after hitting start button in telegram messenger code didn't run. code in activationtype.conversationupdate

foreach (var item in message.membersadded)                 {     try     {         using (var dbcontext = new watermarkbotdbentities())         {             dbcontext.botusers.add(new botuser()             {                addedfriends = 0,                conversationid = message.conversation.id,                serviceurl = message.serviceurl,                userid = message.from.id             });          dbcontext.savechanges();          if (request.requesturi.query != "")          {              var u = dbcontext.botusers.where(x => x.botsalcode == request.requesturi.query.replace("?start=", string.empty)).firstordefault();              u.addedfriends++;              dbcontext.entry(u).state = system.data.entity.entitystate.modified;              if (u != null)              {                  var connector = new connectorclient(new uri(u.serviceurl));                  imessageactivity newmessage = activity.createmessageactivity();                  newmessage.type = activitytypes.message;                 //newmessage.from = new channelaccount("<botid>", "<botname>");                 newmessage.from = new channelaccount("c3e7mhdafcecn7ng3", "bot");                 newmessage.conversation = new conversationaccount(false, u.conversationid);                 newmessage.recipient = new channelaccount(u.userid);                 if (u.addedfriends <= 2)                     newmessage.text = $"sometext.";                 else newmessage.text = "sometex";                 await connector.conversations.sendtoconversationasync((activity)newmessage);                  dbcontext.savechanges();            }         }     } } catch (exception ex) { } 

so how possible detect hitting start in telegram ? regards

i realize not complete answer, wanted share code in case may help. below recommended way send welcome message, may able repurpose code use.

else if (message.type == activitytypes.conversationupdate || message.type == activitytypes.message)             {                 iconversationupdateactivity iconversationupdated = message iconversationupdateactivity;                 if (iconversationupdated != null)                 {                     connectorclient connector = new connectorclient(new system.uri(message.serviceurl));                      foreach (var member in iconversationupdated.membersadded ?? system.array.empty<channelaccount>())                     {                         // if bot added,                         if (member.id == iconversationupdated.recipient.id)                         {                             var reply = ((activity)iconversationupdated).createreply(                             $"hi! i'm botty mcbot.");                             await connector.conversations.replytoactivityasync(reply);                         }                     }                 }             } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -