dateFormatter(...) is not a function if message Timestamp older than 2 days
See original GitHub issueVersion
I using CDN JavaScript version of webchat (see Additional context for code)
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
versions
<meta name="botframework-directlinespeech:version" content="4.8.0">
<meta name="botframework-webchat:bundle:variant" content="full">
<meta name="botframework-webchat:bundle:version" content="4.8.0">
<meta name="botframework-webchat:core:version" content="4.8.0">
<meta name="botframework-webchat:ui:version" content="4.8.0">
Describe the bug
I use client.Conversations.SendConversationHistoryAsync(activity.Conversation.Id, transcript, ct)
to restore 6 last messages in Conversation after (activity.Name == "webchat/join")
triggered.
Everything worked fine until recently when a new issue was discovered:
if message timestamp older than 2 days
var date = DateTime.Now.AddDays(-5);
msgUser.Timestamp = date; //coreRequest.Timestamp;
I recieve that error in browser after SendConversationHistoryAsync call on backend
TypeError: (0 , i.default)(...).dateFormatter(...) is not a function
at t.default (webchat.js:2)
at webchat.js:2
at f (webchat.js:2)
at Ji (webchat.js:2)
at webchat.js:2
at Ha (webchat.js:2)
at Wa (webchat.js:2)
at Rs (webchat.js:2)
at Ps (webchat.js:2)
at Ms (webchat.js:2)
otherwise
var date = DateTime.Now.AddDays(-2);
msgUser.Timestamp = date; //coreRequest.Timestamp;
everything works fine
I presume it’s somehow connected to date format of older messages
Steps to reproduce
- Get index.html from index.zip
- Place your own token on line 50
- Catch activity webchat/join in webhook
if (activity.Name == "webchat/join")
{
HostingEnvironment.QueueBackgroundWorkItem(async ct =>
{
var client = CreateClient(activity, credentials);
var transcript = await _coreTalkService.GetHistoryAsync(new BotToken(userToken, botName), activity);
if (transcript.Activities.Any())
await client.Conversations.SendConversationHistoryAsync(activity.Conversation.Id, transcript, ct);
});
}
- Construct transcript object
public async Task<Transcript> GetHistoryAsync(BotToken botToken, Activity referenceActivity)
{
var result = new Transcript(new List<Activity>());
var activityUser = referenceActivity.From;
var activityBot = referenceActivity.Recipient;
using (var analytics = new AnalyticsClient())
{
var requests = ...
int id = 0;
foreach (var coreRequest in requests)
{
var msgUser = (Activity)Activity.CreateMessageActivity();
msgUser.Id = $"{referenceActivity.Conversation.Id}|{(++id).ToString().PadLeft(7, '0')}";
msgUser.Conversation = referenceActivity.Conversation;
msgUser.ChannelId = referenceActivity.ChannelId;
msgUser.From = activityUser;
msgUser.Recipient = activityBot;
msgUser.Text = coreRequest.Message;
var date = DateTime.Now.AddDays(-2);
msgUser.Timestamp = date;//coreRequest.Timestamp;
var msgBot = msgUser.CreateReply(coreRequest.Response);
msgBot.Id = $"{referenceActivity.Conversation.Id}|{(++id).ToString().PadLeft(7, '0')}";
msgBot.Timestamp = date;//coreRequest.Timestamp.Value.AddSeconds(5);
if (msgUser.Text != "PUSH REQUEST")
result.Activities.Add(msgUser);
result.Activities.Add(msgBot);
}
}
return result;
}
- Change
var date = DateTime.Now.AddDays(-2);
to reproduce the problem
Expected behavior
I expect older messages with localized timestamps shown
Additional context
Web chat function
(async function () {
// add hooks to connect event
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
// When we receive DIRECT_LINE/CONNECT_FULFILLED action, we will send an event activity using WEB_CHAT/SEND_EVENT
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
value: { language: window.navigator.language }
}
});
}
if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY') {
//console.log(action);
}
return next(action);
});
function customRenderMarkdown(text)
{
console.log(text);
const options = { markdownRespectCRLF: true };
var rendered = renderMarkdown(text, options);
console.log(rendered);
return rendered;
}
window.WebChat.renderWebChat(
{
directLine: window.WebChat.createDirectLine({
token: '...'
}),
store,
renderMarkdown: customRenderMarkdown,
userID: '123web', // TODO: change to proper ID
username: 'test@user.name', // TODO: change to proper Name
locale: 'en-US',
// стиль https://github.com/Microsoft/BotFramework-WebChat/blob/master/packages/component/src/Styles/defaultStyleOptions.js
styleOptions: {
botAvatarInitials: 'B',
userAvatarInitials: 'U',
hideUploadButton: true
}
},
document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
[Bug]
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Swift - check if a timestamp is yesterday, today, tomorrow, or X ...
In PHP I'd just use mktime to create a new date, based on the start of the day (i.e. mktime(0,0,0) ), but I'm...
Read more >DateTimeFormatter (Java Platform SE 8 ) - Oracle Help Center
The ISO date formatter that formats or parses a date with an offset, such as '2011-12-03+01:00'. This returns an immutable formatter capable of...
Read more >MySQL 8.0 Reference Manual :: 12.7 Date and Time Functions
TIMESTAMP (), With a single argument, this function returns the date or datetime expression; with two arguments, the sum of the arguments.
Read more >Date and time - The Modern JavaScript Tutorial
Returns the timestamp for the date – a number of milliseconds passed ... Let's say we need to increase the date “28 Feb...
Read more >Hive Date and Timestamp Functions | Examples
– Function from syntax1 has been deprecated; when used it returns the system timestamp. – The other two functions take date, timestamp strings,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@stevkan This is related to #3039 . That issue might provide some more context for helping you repro the issue.
@stevkan Not sure if this helps but I can’t successfully load transcript files in the bot emulator older than 2 days. A work around for me was to change the system time of my windows machine to a date before the timestamp of the conversation and to restart the bot emulator.
You can reproduce it with one of the official transcript files which will not load (white screen of the webchat) in the latest bot emulator. https://microsoft.github.io/botframework-solutions/skills/samples/transcripts/