howdyai / botkit

Botkit is an open source developer tool for building chat bots, apps and custom integrations for major messaging platforms.
MIT License
11.38k stars 2.29k forks source link

Send proactive message on MS teams #2202

Closed khushleen closed 2 years ago

khushleen commented 2 years ago

Hi, I am trying to send the proactive notification(1:1 user) on MS teams using botkit. I checked all the documentation and wrote the below code, but I am not getting success. It is neither showing any error nor sending a message.

var options = { serviceUrl: <--URL-->,
clientId: botframeworkClientId,
    clientSecret: botframeworkClientSecret

}

var bot =  controller.spawn(options);

var param = {
    "bot": {
        "id": "2*:7****",
        "name": "<--BOT NAME-->"
    },
    "isGroup": false,
    "raw_message":{"from":{"id": "2*:1******",
      "name": <--USER NAME-->}},
    "members": [
        {
            "id": "2*:1******",
            "name": <--USER NAME-->
        }
    ],
    "channelData": { "tenant": { "id": "66039c4b-2333-4d9e-89fd-02f94d0d71bd" } },
    "conversation": {
    "conversationType": "personal",
    "tenantId": "6******",
    "id": "a:1*******"
  },
    "user": "2*:1******",
  "channel": "a:1*******"
}

bot.startPrivateConversation(param,function(err,con_id){

con_id.say(param, "Hi, I'm Plato.")
})

Please suggest the method/function which will be used to send a message from bot to the user without any message/activity/event initiated from the user.

benbrown commented 2 years ago

For Teams, use the bot.startConversationWithUser method...

https://github.com/howdyai/botkit/blob/main/packages/botkit/src/botworker.ts#L274

kk-roambee commented 2 years ago

I got success by using addMessageToConversation() to send the proactive notification to the user. Here is the sample code, I have used for your reference:

`

var config_obj = { clientId: <-- APP ID -->, clientSecret: <--SECRET -->, serviceUrl: <-- URL --> }

input_param = { "recipient":{"id":"29:*","name":<--USERNAME-->}, "type":"direct_message", "from":{"id":"28:","name":<--BOTNAME-->}, "conversation":{"conversationType":"personal","tenantId":,"id":"a:"} }

teamsapi = teamsapi_maker(config_obj) teamsapi.getToken(function(){ teamsapi.addMessageToConversation(input_param.conversation.id, input_param, function(){ }) })

`