question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Supply history on startup

See original GitHub issue

Some folks are interested in initializing WebChat with a history.

Since DirectLine doesn’t archive messages, the bot would have to archive them separately.

Here are a couple of possible approaches:

  • The web page could get the archived message out of band, e.g. by calling an endpoint provided by the bot. Then passes those to a new property and/or API in WebChat.
  • The Bot Framework could enable a hook on the channel side where the bot supplies an archiveProvider of some kind. If it exists, DirectLine sends those messages to the WebChat. This has the advantage of working with any deployment of WebChat out of the box, but requires a lot of new plumbing in the Bot Framework.

This is clearly half-baked so I’m opening up a dialog.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:18
  • Comments:77 (21 by maintainers)

github_iconTop GitHub Comments

4reactions
ancashoriacommented, Sep 13, 2017

@morphaxceed here’s the full code:

import { Chat } from 'botframework-webchat'

export interface IMessage {
  from: string,
  text: string,
  attachments?: any[],
  date?: string,
}

class SuperChat extends Chat {
  constructor(props: IProps) {
    super(props)
    const history = this.buildHistory(
      props.conversation.messages,
      0,
      props.conversation.customerAddress,
      props.user.id
    )
    this.injectMessages(history)
  }

  buildHistory(messages, startIndex, customerAddress, agentId) {
    const conversationId = customerAddress.conversation.id
    const customerName = customerAddress.user.name
    return messages.map((message, messageIndex) => ({
      type: "message",
      text: message.text,
      from: {
        id: message.from === 'agent' || message.from === 'bot' ? agentId : '',
        name: message.from === 'user' ? customerName : message.from
      },
      attachments: message.attachments,
      timestamp: message.date,
      id: `${conversationId}|${startIndex + messageIndex}`,
    }))
  }

  injectMessages(messages: any[]) {
    messages.forEach(activity => {
      this.store.dispatch({
        type: 'Receive_Message',
        activity
      })
    })
  }
}

customerAddress is created by botframework and you can get it from session object Here’s the interface for customerAddress https://docs.botframework.com/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.iaddress.html

In buildHistory() I do extra checks that you don’t need. Make sure you return the same object structure and you should be fine. Also, this code is tested only on webchat version 0.10.8

Hope it helps

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Short History of Supply Chain Management – Logmore Blog
In the late 1920s, the introduction of mass production along assembly lines laid the foundations for supply chain management. First successfully ...
Read more >
432 startup failure post-mortems - CB Insights
It's hard to say goodbye. Find out how 432 startups have failed and why in the words of their investors and founders.
Read more >
Startup Lessons from History: Sun Tzu | by Aki Ranin - Medium
This ongoing series is an exploration and tribute to what history can teach us about startups, and life itself.
Read more >
Supply Chain Startup Stord Adds $120M To Series D, Now ...
Atlanta-based Stord is the latest supply chain startup to pocket a large tranche of money, as it announced an additional $120 million to...
Read more >
How to Check Shutdown and Restart History on Linux
Getting information about the last shutdowns and reboot history is rather easy on Linux.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found