Proactive message not working in MS Teams after bot is restarted - botframework

I have a proactive messaging endpoint that works fine when a user is actively engaged in a conversation. For example, one use case where user asks for invoice data to be retrieved, which happens asynchronously and is sent back via proactive message. This works fine. But if a try to continue a conversation weeks later, the continueConversation action is failing. If I go into teams and initiate a new conversation with the bot, then resending the proactive message (without changing anything) works again.
In one of my use cases, the bot needs to follow up with the user 1+ weeks in the future. So I need to figure out how to send a proactive message to a teams user even if they haven't recently conversed with the bot. I'm not sure why continueConversation isn't working because the conversation ID doesn't change (and hasn't changed in months, probably not ever).
Here is the function I am using to send the proactive message.
server.post('/api/notify', async (req, res) => {
//console.log(req.body);
try {
const conversationReference = req.body.conversationReference;
await adapter.continueConversation(conversationReference, async turnContext => {
// If you encounter permission-related errors when sending this message, see
// https://aka.ms/BotTrustServiceUrl
await turnContext.sendActivity(req.body.message);
});
res.setHeader('Content-Type', 'text/html');
res.writeHead(200);
res.write('<html><body><h1>Proactive messages have been sent.</h1></body></html>');
res.end();
} catch (error) {
console.log('Bad Request. Please ensure your message contains the conversation reference and message text.');
console.log(error);
appInsightsClient.trackTrace({
message: `${error.name} - ${path.basename(__filename)}`,
severity: 4,
properties: {'error':error.message,'callStack':error.stack, 'botName': process.env.botName}
});
res.setHeader('Content-Type', 'text/html');
res.writeHead(400);
res.write('<html><body><p>Bad Request. Please ensure your message contains the conversation reference and message text.</p></body></html>');
res.end();
}
});

As the link in my own code says,
If your bot is restarted, a user awaiting a proactive message cannot receive it unless they have messaged the bot again after it restarted.
So that was exactly what the issue was. But the instructions on that page aren't giving the full details. You have to add the class via const { MicrosoftAppCredentials } = require('botframework-connector') as well as set the serviceUrl to pass (which is already available at conversationReference.serviceUrl).
So with these changes I added MicrosoftAppCredentials.trustServiceUrl(conversationReference.serviceUrl); before I send the proactive message and it started working fine even after bot was restarted.

Related

Zabbix timing out when sending Slack notification, but alerts are still send

I have a question regarding the Slack Webhooks for Zabbix. I've configured Zabbix to send Slack messages when a trigger of any kind is triggered. However the alerts are send, but zabbix does not recognize that the messages have been send, as seen in the pictures below:
Slack Alerts
Slack Problem
The Error messages state: Slack notification failed : Error: cannot get URL: Timeout was reached
Resolved Message: Slack notification failed : channel_not_found
I've followed this tutorial for the Slack intergration.
My configuration is as follows:
Actions,
Zabbix Admin user Media
on Zabbix 4.4.7
Hopefully someone can help me with this!
if you use HTTPProxy parameter, modify script as follows:
function getPermalink(channelId, messageTimestamp, httpProxy) {
var req = new CurlHttpRequest();
if (typeof httpProxy === 'string' && httpProxy.trim() !== '') {
req.SetProxy(httpProxy);
}
and
result.tags.__message_link = getPermalink(resp.channel, resp.ts, params.HTTPProxy);

Bot Framework API, reply to messages

I have registered Bot channels on Azure portal and enabled Skype support. I'm trying to create a reply to skype messages as described here.
I get user's message like: { ... 'type': 'message', 'id': '1579000...' ... }
And then use that id when sending POST to .../v3/conversations/{conversationId}/activities/1579000...
In a request body I also have 'replyToId': '1579000...'
The message, which is sent to skype, comes up without any quote inside (as usual message). What am I doing wrong? Do I understand how it should actually work (maybe this is not quoting, but something else)?

Multiple user sessions not receiving subscription message - spring stomp websocket

I am using Spring stomp websocket framework to send subscription messages to the clients. We are using ActiveMQ as the message broker
and is using a stomp javascript client. Spring 4.1.5 and In this architecture, the messages are sent using
simplemessagingTemplate.convertAndSendToUser(user, "/queue/msg", serverMsg, map);
In order to ensure that only the right user receive their message, I am also making use of a QueueSubscriptionInterceptor that implements ChannelInterceptor.
The messages are delivered to the destination correctly. The messages are received using the JS client like this.
stompClient.subscribe('/user/guest/queue/msg', function(greeting){
x = JSON.parse(greeting.body);
...
}
So far so good. However, when there are multiple user session, only one session receives the message. For (e.g), if two "guest" users
are logged in, I would like all the two "guest" users to receive the message. This doesnt seem to be happening. Looking into the logs,
I see that the message seems to be sent..
2015-04-11 14:39:40 DEBUG StompBrokerRelayMessageHandler:738 - Forwarding SEND /queue/msg-user1 session=_system_ application/json;charset=UTF-8 payload={"my message to you...)
2015-04-11 14:39:40 DEBUG StompBrokerRelayMessageHandler:738 - Forwarding SEND /queue/msg-user0 session=_system_ application/json;charset=UTF-8 payload={"my message to you...)
I see only one client receiving the message and not the other. Reading the Spring documentation, I understand that this is the default behaviour.
Can someone tell me what I am doing wrong.
Thanks.
You should use the semantic of topics instead of queues.
A queue allows the message to be consumed once, but a topic will allow it to be consumed once per subscriber. So something like /topic/user/guest/msg probably would do it.
Set the ack header in the connect frame. What this will do is that the server will continue to send you the same message until you send back an ack frame. Which I am doing below by calling greeting.ack() as soon as receive the message. Setting it to 'client-individual' will mean that the server has to receive ack from all sessions of the particular client or it will keep re sending the same msg on every CONNECT.
Hope this helps!!
Use below code for reference.
function connect() {
var socket = new SockJS('/powerme-notification-websocket');
stompClient = Stomp.over(socket);
stompClient.connect(
{client_id:'testClient'}, function (frame) {
setConnected(true);
console.log('Connected: ' + frame);
stompClient.subscribe('/user/topic/releaseLock', function (greeting) {
stompClient.subscribe('/queue/releaseLock-testClient', function (greeting) {
console.log(greeting);
showGreeting(greeting.body);
greeting.ack();
},{durable:true,
'auto-delete':false,
ack:'client-individual',
id:'testClient'});
});
}
References:
https://stomp.github.io/stomp-specification-1.2.html#ACK

sails.js + socket.io: Can't receive standard sail.js/socket.io messages on client

With the newest beta version from sails.js (0.10.0-rc5) I'm trying to do this:
sails new Test
cd Test
sails generate api user
Create file assets/js/test.js
var socket = io.connect('http://localhost:1337');
socket.on('connect',function() {
console.log('connected');
socket.request('/user',{}, function(users) {
console.log(users);
});
socket.on('message', function(msg) {
console.log("Message: " + msg);
});
socket.on('user', function(msg) {
console.log("User: " + msg);
});
});
My problem
console.log("User: " + msg); and console.log("Message: " + msg); aren't receiving any messages when I create or update a user.
According to the documentation and to the Intro to sails.js video this socket.io messages should be send automatically.
What am I missing to successfully receive sails.js/socket.io message on my client?
If you installed the latest NPM version, then you'll also have the latest version of the Sails socket client. Check out its page on Github for basic usage, then check out the PubSub section of the Sails migration guide, which explains the differences between Sails v0.9.9x (which the Intro to Sails.js video shows) and the latest version. In the end, your code should look more like:
// Note--the latest sails socket client connects automatically!
// Get all of the existing users--also subscribes to socket events
// for those users
io.socket.get('/user', function serverResponded (body, sailsResponseObject) {
console.log(body);
});
// When a socket message about a user is received, display it
io.socket.on('user', function(data) {
console.log(data);
});
Notes
Pay special attention to the section in the migration guide about .watch(); it means that you don't get create events automatically anymore and have to subscribe to them in your server code using (for the User model) User.watch().
Remember that in general you don't get socket messages about actions that you yourself trigger, so if you want to test that your message-handling code is working, it's best to open up two windows (or tabs) and do your requests in one while watching for events in the other.
Also remember that you only get subscribed to socket events when you make a socket request; an AJAX call to /users will retrieve all of the current users, but you won't be subscribed to events. It has to be done using io.socket.get.

PushNotification Staus Code 200 but not Receiving Message

After successfully sent the URI to the web service from the push client, I send a toast notification from web service by using the URI, in web service I get the response as :
Push status 200,
NotificationStatus : Received,
DeviceConnectionStatus : Connected,
NotificationChannelStatus : Active.
But no message is received in the push client. The same scenario used to work fine earlier today. Can anyone tell me what is going wrong?
Is the message you are sending the same (ie. identical)? I seem to remember that some instances of a malformed message would get through the service OK, but then be suppressed on the device.
Do you have code to handle toast messages that arrive while your app is running? If you do, put a breakpoint in there and send a toast to the app while you're debugging and see what comes out. In this way you can make sure that the toast is making it to the device, and also see what the content is or what the problem might be.
channel.ShellToastNotificationReceived += channel_ShellToastNotificationReceived;
where channel is your channel object, and then
void channel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
{
Dispatcher.BeginInvoke(() => MessageBox.Show(e.Collection["wp:Text1"] + Environment.NewLine + e.Collection["wp:Text2"]));
}
or something similar to pop the message out to the display.
In web service, if a wrong setRequestProperty is set for example, setting wrong X-WindowsPhone-Target and wrong X-NotificationClass, then web service will receive notification received status, but the push client will not receive any message.
In my case I was sending a toast message with X-WindowsPhone-Target as token and X-NotificationClass as 1. After giving correct value it has started working fine.

Resources