In Microsoft Bot Framework - botbuilder v.3.15.0
When opening url from bot without any query strings - it perfectly works - and opens external url (previously defined var urlExt, or just plain 'https://some.html') when clicking on a button in the bot... - in Bot Framework Emulator, Azure Web Chat, Messenger & Telegram - perfectly ok.
lib.dialog('/', [
function (session, args) {
args = args || {};
// var pkey1 = 'fdsa'; // dummy variable, url with querystring with this dummy works ok on all channels!
// var rkey1 = 'asdf'; // dummy variable, url with querystring with this dummy works ok on all channels!
var pkey1 = session.logger.address.conversation.id;
var rkey1 = session.logger.address.user.id;
console.log(pkey1); // correctly shows conversation id in console locally
console.log(rkey1); // correctly shows user id in console locally
var urlMap = `https://mymap.azurewebsites.net/?cid=${pkey1}&uid=${rkey1}`;
var urlExt = encodeURI(urlMap);
setTimeout(function () {
var addressCard = new builder.HeroCard(session)
.title('address_title')
.subtitle('address_subtitle')
.images([
new builder.CardImage(session)
.url('https://somedb.blob.core.windows.net/images/ab_small.png')
.alt('Here comes some pic')
])
.buttons([
builder.CardAction.openUrl(session, urlExt, 'Just do it!')
]);
session.send(new builder.Message(session)
.addAttachment(addressCard));
}, 1000)
},
function (session, results) {
// some further code
}
]);
But when you try to insert query string into urlExt - by taking it's parameters conversation.id and user.id from 'session' - by making variables who take values of conversation.id and user.id from 'session' and then inserting those variables into urlExt (either by '+' concatenation, or by `` ${} method) it works locally in Emulator - but not on Azure Web Chat or Messenger or Telegram.
When I try to find the reason for this problem I tried not to grab conversation.id or user.id from 'session', but just insert some dummy variables with text to forward them into html page by inserting those variables as part of the query string - IT WORKS...:(
Really strange, the problem seems to be with getting conversation.id & user.id from 'session' to variables at Azure Portal.
But why does it perfectly work locally on my laptop?
Logs on Azure say that:
TypeError: Cannot read property 'conversation' of undefined
I have looked in stackoverflow - there is ZERO info about it, I looked at the various code at GitHub - NO ANSWERS...
Please, hint, or help...
The session logger is only enabled on certain channels, which is why your code works in the emulator but not in Test in WebChat on Azure and Microsoft Teams. Instead of getting the conversation and user ids from the logger attribute, access them from the message property.
var pkey1 = session.message.address.conversation.id;
var rkey1 = session.message.address.user.id;
Hope this helps!
Related
I am currently using Nodejs to have post multiple html files I have
app.get('/',function (req,res) {
//console.log(Date().toString() +'\n' + "Client side Viewing.........\n");
res.sendFile('C:\\Users\\Documents\\Document\\F10N_MFG\\Commit\\Commit.html');
});
app.get('/Commit_Edit',function (req,res) {
//console.log(Date().toString() +'\n' + "Client side Viewing.........\n");
res.sendFile('C:\\Users\\Documents\\Document\\F10N_MFG\\Commit\\Commit - Edit.html');
});
and I use SocketIo to pass variable around from client to server and server back to client
I want to have a page that collect a client selection (variable) and pass back to server and the server will trigger that client-side to open a new browser tab that bring over the variable he choose only to that specific client
and meanwhile not changing other clients selection.
is it possible?
for now,
I have an solution by including the variables in link address
I added the variable in the link and run it
http://mfgrpa2:4000/lot_list?param=value/
var x = window.location.href.search("param=");
var y = window.location.href.substring(x+6,window.location.href.length);
var z = y.replaceAll("%20"," "); //replace any %20 to space;
console.log(z);
and it works.
I am working on use of serial port access with chrome browser, using "navigator.serial".
My initial experiment is based on a prior posting to stackoverflow:
Is there an example site that uses navigator.serial?
I have duplicated the code example referenced above, and have made the required configuration change #enable-experimental-web-platform-features, again as described above.
I am doing this all on Ubuntu 18.04. There are two USB serial ports attached to the machine, and I have verified using gtkterm that I can send and receive data between the two ports.
From the example given (code duplicated below), I find that I can open the serial port and establish a "reader", and the step await reader.read() does wait until an incoming character appears on the serial port, but at this point the variabler/object "data" remains undefined.
Two questions/issues:
What am I doing wrong that leaves "data" undefined? I added an alert() dialog box that pops up once const {done, data} = await reader.read(); proceeds, however, the dialog box says that "data" is at that point undefined. Is data a promise that I am failing to wait to be fulfilled?
I have not been able to find a (hopefully self-contained) reference on the methods and members of the classes involved (i.e., reader.read() and reader.write() are methods available to my object "readeer"; where can I find a list of available methods, and the properties of these?
Here is a copy of the code (small web page) that was obtained from the year-ago posting above:
<html>
<script>
var port;
var buffy = new ArrayBuffer(1);
var writer;
buffy[0]=10;
const test = async function () {
const requestOptions = {
// Filter on devices with the Arduino USB vendor ID.
//filters: [{ vendorId: 0x2341 }],
};
// Request an Arduino from the user.
port = await navigator.serial.requestPort(requestOptions);
// Open and begin reading.
await port.open({ baudrate: 115200 });
//const reader = port.in.getReader();
const reader = port.readable.getReader();
writer = port.writable.getWriter();
//const writer = port.writable.getWriter();
//writer.write(buffy);
while (true) {
const {done, data} = await reader.read();
if (done) break;
console.log(data);
}
} // end of function
</script>
<button onclick="test()">Click It</button>
</html>
Thank you for any assistance!
I was having the exact same problem and managed to solve it.
Change
const {done, data} = await reader.read();
To
const {value, done} = await reader.read();
The example where you got this from (and a few others) were wrong, params around the wrong way.
Also, not too sure why but when I used
const {data, done} = await reader.read();
it did not work either, it did not like the var data.
Documentation on navigator.serial is not great. Here are some links to help
The API (note this is draft and does not exactly match the Chrome implementation)
https://wicg.github.io/serial/
port.readable.getReader() is a ReadableStream
https://streams.spec.whatwg.org/#readablestream
that uses ReadableStreamDefaultReader which is defined as
dictionary ReadableStreamDefaultReadResult {
any value;
boolean done;
};
https://streams.spec.whatwg.org/#readablestreamdefaultreader
An explainer
https://github.com/WICG/serial/blob/gh-pages/EXPLAINER.md
A tutorial
https://codelabs.developers.google.com/codelabs/web-serial
Chromium tracker
https://goo.gle/fugu-api-tracker
The Web Serial API work item
https://bugs.chromium.org/p/chromium/issues/detail?id=884928
How to make html view/template that updates with new data from changed file
I am developing a chat messenger service and am storing messages in a SQL database i have made a similar file checking function like above question.
Is there anyway to add the output of this function into the html every time a new change to the database is detected?
You haven't gone in to much detail on what you're using to do this, but I'm going to answer and assume you're working with SocketIO.
Is there anyway to add the output of this function into the html every time a new change to the database is detected?
This is probaby the wrong way to think about this. The question you linked deals with tailing a file, and then acting appropriately. You shouldn't need to detect a database change, since your event function should be handling all the messages.
I created a gist of a very basic chat app which includes the functionality you desicribe. (Based on a tutorial which is linked in the README).
You should have a function which handles an incoming message from a user, then emits it on the socket, so other users on the system will see that message. This is where you want to update your database:
#socketio.on('my event')
def handle_my_custom_event(json, methods=['GET', 'POST']):
""" handle an incoming chat message, add to db, then emit to room """
# Unique ID for the session
json['sid'] = request.sid
print('received my event: ' + str(json)) # Just prints to server terminal
# Build the database entry and commit
new_db_entry = ChatHistory(sid = json['sid'],
message = json['message'],
username= json['user_name'])
db_session.add(new_db_entry)
db_session.commit()
# Escape nasty html. Do this for each var the user enters
json['user_name'] = su.escape(json['user_name'])
json['message'] = su.escape(json['message'])
socketio.emit('my response', json, callback=messageReceived)
You then have some corresponding Javascript which recieves this event in the frontend, and updates the HTML:
socket.on( 'my response', function( msg ) {
if( typeof msg.user_name !== 'undefined' ) {
$( 'div.message_holder' ).append( '<div><b style="color: #000">'+msg.user_name+'</b> '+msg.message+'</div>' )
}
})
However how do you render the history in a user's browser when they first connect? You could write some Javascript to do this, however my example simply queries the database when a user first renders the session.html template (the frontend):
#app.route('/')
def sessions():
history = ChatHistory.query.all()
return render_template('session.html', history=history)
And then in the corresponding template, builds the page at load time:
<div class="message_holder">
{% for chatItem in history %}
<div><b style="color: #000">{{ chatItem.username }}</b> {{ chatItem.message }}</div>
{% endfor %}
</div>
This is just a sample of what can be done.
I have written a WebAPI controller method that finds a mail by its unique ID from ExchangeOnline. I wrote a small model class in order to store some attributes of a mail like the subject, the sender, the date received and so on.
Now I also want to access file attachments if the mail has such attachments. Therefore, I wrote this code (just the relevant part):
List<AttachmentItem> attDataContainer = new List<AttachmentItem>();
EmailMessage originalMail = EmailMessage.Bind(service, new ItemId(uniqueID), new PropertySet(ItemSchema.Attachments));
foreach (Attachment att in originalMail.Attachments)
{
if (att is FileAttachment && !att.IsInline)
{
FileAttachment fa = att as FileAttachment;
fa.Load();
attDataContainer.Add(
new AttachmentItem
{
ID = fa.Id,
Name = fa.Name,
ContentID = fa.ContentId,
ContentType = fa.ContentType,
ContentLocation = fa.ContentLocation,
Content = Convert.ToBase64String(fa.Content),
Size = fa.Size
});
}
}
The method indeed finds the attachments and displays all of the attributes you can see in the "AttachmentItem" object - BUT NOT the fa.Content attribute.
I have crwaled almost any document I could find on this (especially the *.Load() part as well as much examples. But in my case I get "byte[0]" when debugging the output.
Do you have any idea for me what could be the reason for this?
PS: By the way, I have version v2.0.50727 of Microsoft.Exchange.WebServices referenced.
Best regards and thanks in advance,
Marco
When you call the load method on the Attachment that should make a GetAttachment request to the server which will return the data for that Attachment. If you enable tracing https://msdn.microsoft.com/en-us/library/office/dn495632(v=exchg.150).aspx that should allow you to follow the underlying SOAP requests which should help with troubleshooting (eg you can see what the server is returning which is important).
The other thing to check is that is this is a real attachment vs a One Drive attachment which could be the case on ExchangeOnline.
i am implementing TAG based push notification in windowsphone8 but my app is not able to register the TAG when i execute following code.
i have tried putting subscribeTag outside onReadyToSubscribe too but i am not getting anything no success , no failure , no nothing.
if (WL.Client.Push) {
WL.Client.Push.onReadyToSubscribe = function() {
WL.Client.Push.subscribeTag("RRNEWS", {
onSuccess: function () {
alert("Tag registered");
},
onFailure: function (e) {
alert("Tag registered failed" + JSON.stringify(e));
}
});
};
}else{
alert("not supported");
}
i have register tag in application-descriptor.xml as follows
<tags>
<tag>
<name>RRNEWS</name>
<description>News</description>
</tag>
</tags>
here is the windowsphone8 entry
<windowsPhone8 version="1.0">
<uuid>6e043ba2-d382-4894-965f-47e08c24bd1e</uuid>
<pushSender/>
</windowsPhone8>
I run a tag based notification sample from Tag Notification github and deployed it on my mobile first server 6.3
when i generated the windowspone8 build and run it into a device , it shows following results
1) isPushSupported -> True
2) isSubscribed -> sample-tag1: false , sample-tag2: false
rest of the buttons are disabled
1) Subscribe to sample-tag2
2) Unsubscribe from sample-tag1
3) Unsubscribe from sample-tag2
then i tried removing disabled properties from html tag and try pressing
subscribe to sample-tag2 but nothing is happening.
Change is adapter code
function sendTagNotificationToWindows(applicationId, notificationText,notificationTags){
var notificationOptions = {};
var tags = notificationTags.split(",");
var notificationOptions = {};
var notification = WL.Server.createDefaultNotification(notificationText, 10);
notification.MPNS.raw = {};
notification.MPNS.raw.payload = {"custom":"data"} ;
notificationOptions.message = {};
notificationOptions.target = {};
notificationOptions.message.alert = JSON.stringify(notification);
notificationOptions.target.tagNames = tags;
// i have tried it with a notificationOptions too
WL.Server.sendMessage(applicationId, notification);
return {
result : "Notification sent to users subscribed to the tag(s): '" + JSON.stringify(notification) + "'."
};
}
Error
when i pass only notification param it throws following error
"Push Works Bad Request: FPWSE0005E: Invalid value was provided. Check the 'message' parameter value."
The Tag notifications sample project does not take into account the Windows Phone 8 environment. Here's what you need to add to the sample:
application-descriptor.xml
After adding the Windows Phone 8 environment, add an empty pushSender tag:
<windowsPhone8 version="1.0">
<uuid>AUTOGENERATED-GUID-NUMBER-HERE</uuid>
<pushSender/>
</windowsPhone8>
PushAdater-impl.js
Add the following to the function used for sending the notification.
For example, something like this:
function sendTagNotification(applicationId, notificationText, notificationTags) {
var tags = notificationTags.split(",");
var notificationOptions = {};
notificationOptions.message = {};
notificationOptions.message.alert = notificationText;
notificationOptions.target = {};
notificationOptions.target.tagNames = tags;
notificationOptions.settings = {};
notificationOptions.settings.mpns = {};
notificationOptions.settings.mpns.toast = {};
notificationOptions.settings.mpns.toast.text1 = "New notification";
notificationOptions.settings.mpns.toast.text2 = "You have a new notification";
notificationOptions.settings.mpns.toast.param = "/MainPage.xaml?value1=54321";
WL.Server.sendMessage(applicationId, notificationOptions);
return {
result : "Notification sent to users subscribed to the tag(s): '" + notificationTags + "'."
};
}
notificationOptions.settings.mpns.toast is needed so that when the application is closed (quit) or in the background, "toast" notification type will appear in the device.
Tapping on a toast notification launches the application. optional "param" field is used to pass on values that will be displayed once the application launches. The values set in the "param" of the toast can be retrieved natively and displayed within the application.
Additional clarifications:
When the app is open the raw notification type and the props and payload values can be seen on screen if used.
When the app is in the background and tapping the notification there are two notification types that can be receive: toast or tile. Both open the application.
When the app is in the background and tapping the app icon:
This means clicking the application tile. Application launches
When the app is closed and tapping the notification: Tapping on the toast launches the application. Tapping on the application tile launches the application.
When the app is closed and tapping the app icon: This means clicking the application tile. Application launches
I recommend to read the following MS documentation to understand what are the available notification types (Toast, Tile and Raw) and when to use them: https://msdn.microsoft.com/en-us/library/hh221549.aspx
Then search for "MPNS", "toast", "tile" or "raw" in the following user documentation topic (for onMessage) to see an example of how to set them up in your application: http://www-01.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.apiref.doc/html/refjavascript-server/html/WL.Server.html?cp=SSHS8R_7.1.0%2F10-1-0-1-6&lang=en