MS Teams Dialog Bot Event Not Fired when message is sent from outside the Teams Bot - event-handling

I am sending a message on an existing conversation to my MS Teams Chatbot from outside i.e. a Windows Forms Application.
ChannelAccount userAccount = originalActivity.From;
ChannelAccount botAccount = new ChannelAccount("GenerateReport", "AzureFunction");
var message = new Activity();//Microsoft.Bot.Schema.Activity.CreateEventActivity();
message.Type = ActivityTypes.Message;
message.From = originalActivity.Recipient; //new ChannelAccount("GenerateReport", "AzureFunction");//botAccount;
message.Value = originalActivity;
((Activity)message).Text = "LongOperationResponse";
message.Recipient = originalActivity.From;// userAccount;
message.ChannelId = originalActivity.ChannelId;
message.Conversation = originalActivity.Conversation;
ResourceResponse response21= await connectorClient.Conversations.SendToConversationAsync((Activity)message);
The message activity is sent successfully and the message appears in the chat bot conversation.
I would also like to somehow trap the event when the above message is received by the ma teams chatbot.
I have attached the following Event handlers in DialogBot class that inherits from ActivityHandler class.
OnMessageActivityAsync
OnEventActivityAsync
OnTurnAsync
However, none of the above event handlers get triggered when the message is sent from outside the bot using the above logic.
These event handlers get triggered only when a user types a message in the chatbot.
Which event should get triggered when an outside message is received by the team's chatbot and how do I handle the event.
Please help.
Thanks
Gagan

The question was a bit unclear, but reading the comments now I think I understand it better. You are sending messages as the bot, but from outside of the bot (basically pro-active messaging). As a result, your bot code won't get notified at all because from Bot Framework's perspective, why would it tell you that you are sending a message - you'd know that already, of course. In practice, you will only get notified:
when a message is sent to your bot
that is further defined depending on conversation type. For a 1-1, you will get ALL messages TO your bot. For a group chat or Teams channel conversation, you will only get messages where you bot is #mentioned

Related

How to send text messages in Jitsi?

I'm developing a standard video call application using Jitsi; I want an additional feature to let the other party know something lik "I'll be late a few minutes"
Jitsi has a built-in text chatting; but I don't know how it can be used outside the Jitsi call.
You can develop with "external_api.js". when current user joined the video jitsi triggers
participantJoined - event notifications about new participants who
join the room. The listener will receive an object with the following
structure:
api.on(‘participantJoined’, (object) => join(object.id));
resource
method will be triggered for each participant. Collect and store the participant "id"'s from there. Then use
sendEndpointTextMessage - Sends a text message to another participant
through the datachannels.
api.executeCommand('sendEndpointTextMessage', 'receiverParticipantId', 'text');
resource2
this method for sending messages for each participant.
You can develop with "lib-jitsi-meet"(lib-jitsi-meet) library and then you can use "sendTextMessage(text)" function.

Display message 'user typing...' to everyone, including sender, if I am typing a message, VUE JS and socket.io

I am using vuejs and socket.io in my application. The task is this: if I type a message in a dialogue with the user, display a message to both the interlocutor and myself, that I am typing a message.
How can I implement this?
Socket.io gives you lots of options to send messages across the board. What I always found very helpful is the Emit cheatsheet from the official docs (https://socket.io/docs/emit-cheatsheet/).
Here are some of the methods on how to broadcast messages to all clients including sender.
io.on('connect', onConnect);
function onConnect(socket) {
// sending to all clients in 'chat' room, including sender
io.in('chat').emit('typing', 'User xy is typing');
// sending to all clients in namespace 'chatNamespace', including sender
io.of('chatNamespace').emit('typing', 'User xy is typing');
// sending to a specific room in a specific namespace, including sender
io.of('chatNamespace').to('chat').emit('typing', 'User xy is typing');
}
Now this of course are just example methods. You would need to wrap this into your own business logic and probably register some socket event listeners to get this going.

Openfire ConversationID has changed after logout

I'm developing a chat app that use XMPPFramework and Openfire Server. When I (usn2) send message to usn1, a message has been created in ofMessageArchieve with conversationID. But after logout and login again, when chat, the new conversation has created (see image below), but I want to add this message to exist conversation. How can I do this?
Code to send message:
let msg = XMPPMessage(type: "chat", to: XMPPJID.jidWithString(getJIDFromName(stateID)))
msg.addBody(message)
msg.addAttributeWithName("id", stringValue: stream.generateUUID())
stream.sendElement(msg)
Although I changed Openfire as #Shoaib Ahmad Gondal suggested. It still happens
MessageId and ConversationId is not same. MessageId generates for each message you send but ConversationId generates based on users & session(maybe). To keep them same you have to modify message archive plugin or develop new one.

Is it possible to have Lync communicate with a REST API?

I have created a basic REST API where a user can ask for an acronym, and the web-page will return the meaning of the acronym via a POST call.
The majority of my end-users don't use the Internet as much as they use the Microsoft Lync application.
Is it possible for me to create a Lync account, and have it pass questions to my API, and return the answers to the user? Meaning the user just needs to open a new chat in Lync rather than a new web-page.
I'm sure this is possible, but I can't find any information on Google or on the web. How can this be accomplished?
Thanks very much.
Edit :
Adding a bounty in the hopes of someone creating a simple example as I believe it would be very useful for a large number of devs :).
Yep, absolutely. UCMA (the Unified Communications Managed API) would be my choice of API to use here, and a good place to start - UCMA apps are "normal" .net applications, but also expose an application endpoint, which can be added to a user's contact list. When users send messages, that can trigger events in your application so you can take the incoming IM, do the acronym translation and return the full wording.
I have a bunch of blog posts about UCMA, but as of yet no defined collection of "useful" posts to work through, but coming soon! In the meantime, feel free to browse the list.
-tom
To elaborate on Tom Morgan's answer, it would be easy to create an UCMA application for this.
Create an UCMA application
Now this doesn't have to be complicated. Since all you want is to receive an InstantMessage and reply to it, you don't need the full power of a trusted application. My choice would be to use a simple UserEndpoint. As luck would have it, Tom has a good example of that online: Simplest example using UCMA UserEndpoint to send an IM.
Make it listen to incoming messages
Whereas the sample app sends a message when it is connected, we need to listen to messages. On the UserEndpoint, set a message handler for instant messages:
endpoint.RegisterForIncomingCall<InstantMessagingCall>(HandleInstantMessagingCall);
private void HandleInstantMessagingCall(object sender, CallReceivedEventArgs<InstantMessagingCall> e)
{
// We need the flow to be able to send/receive messages.
e.Call.InstantMessagingFlowConfigurationRequested += HandleInstantMessagingFlowConfigurationRequested;
// And the message should be accepted.
e.Call.BeginAccept(ar => {
e.Call.EndAccept(ar);
// Grab and handle the toast message here.
}, null);
}
Process the message
There is a little complication here, your first message can be in the 'toast' of the new message argument, or arrive later on the message stream (the flow).
Dealing with the Toast message
The toast message is part of the conversation setup, but it can be null or not a text message.
if (e.ToastMessage != null && e.ToastMessage.HasTextMessage)
{
var message = e.ToastMessage.Message;
// Here message is whatever initial text the
// other party send you.
// Send it to your Acronym webservice and
// respond on the message flow, see the flow
// handler below.
}
Dealing with the flow
Your message flow is where the actual data is passed around. Get a handle on the flow and store it, because it's needed later to send messages.
private void HandleHandleInstantMessagingFlowConfigurationRequested(object sender, InstantMessagingFlowConfigurationRequestedEventArgs e)
{
// Grab your flow here, and store it somewhere.
var flow = e.Flow;
// Handle incoming messages
flow.MessageReceived += HandleMessageReceived;
}
And create a message handler to deal with incoming messages:
private void HandleMessageReceived(object sender, InstantMessageReceivedEventArgs e)
{
if (e.HasTextBody)
{
var message = e.TextBody;
// Send it to your Acronym webservice and respond
// on the message flow.
flow.BeginSendInstantMessage(
"Your response",
ar => { flow.EndSendInstantMessage(ar); },
null);
}
}
That would about sum it up for the most basic example of sending/receiving messages. Let me know if any parts of this need more clarification, I can add to the answer where needed.
I created a Gist with a full solution. Sadly it is not tested because I'm currently not near a Lync development environment. See UCMA UserEndpoint replying to IM Example.cs.
I never used Lync but while I was looking at the dev doc, I stumble upon a sample which could be what you're looking for.
Lync 2013: Filter room messages before they are posted
Once you have filtered the messages, you just need to catch the acronym and call your custom code that calls your API.
Unless I'm missing something, I think you could do it with a simple GET request as well. Just call your API like this yoursite.com/api/acronym/[the_acronym_here].
You can use UCWA (Microsoft Unified Communications Web API),is a REST API.For detail , can reference as the following..
https://ucwa.lync.com/documentation/what-is-lync-ucwa-api

Access muc roster from an ejabberd module (disco_items?)

I'm building an ejabberd module to send carbon copies of messages to an external RESTful API. Everything works okay, and requests to that API are sending POST params with Sender, Recipient and the message Body.
I'm triggering the user_send_packet and user_receive_packet hooks for this, and I can extract the params (Sender, Recipient, Body) from the packet:
Sender = xml:get_tag_attr_s("from", Packet),
Recipient = xml:get_tag_attr_s("to", Packet),
Body = xml:get_path_s(Packet, [{elem, "body"}, cdata])
For group chats (MUC) I'd also like to send the MUC roster (participants) in a parameter, but I don't know how to access them.
Is there an event for this? Can anyone point me to some documentation?
Thanks in advance!
It seems that you want to get MUC participants of specific room.
You need to look at mod_muc.erl and mod_muc_room.erl.
I'm not sure which version of ejabberd you use, so I will explain based on latest ejabberd.
After getting pid of room by calling
mnesia:dirty_read(muc_online_room, {Room, Host})
you can call
gen_fsm:sync_send_all_state_event(Pid, {get_disco_item, From, Lang}, 100)
or use similar code. User list is in the reply.
If you don't like reply format, you may want to add custom handle_sync_event to mod_muc_room.erl .