howdyai / botkit-starter-web

Botkit Anywhere - a starter kit for building a bot that lives in your website or app
https://botkit.ai
MIT License
113 stars 75 forks source link

Internet Explorer: 'Promise' is undefined #14

Closed jackdh closed 5 years ago

jackdh commented 6 years ago

I'm getting the following error when attempting to spin this up and run it in IE.

SCRIPT5009: 'Promise' is undefined
client.js (30,9)

Which links to

return new Promise(function(resolve, reject) {
          var xmlhttp = new XMLHttpRequest();

          xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == XMLHttpRequest.DONE) {
              if (xmlhttp.status == 200) {
                var response = xmlhttp.responseText;
                var message = null;
                try {
                  message = JSON.parse(response);
                } catch (err) {
                  reject(err);
                  return;
                }
                resolve(message);
              } else {
                reject(new Error('status_' + xmlhttp.status));
              }
            }
          };

          xmlhttp.open("POST", url, true);
          xmlhttp.setRequestHeader("Content-Type", "application/json");
          xmlhttp.send(JSON.stringify(body));
        });
Naktibalda commented 6 years ago

Yes, it appears that IE is unsupported since this commit: https://github.com/howdyai/botkit-starter-web/commit/6918855b554c4bb1953617112ab1e7cd55c9ad18

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Browser_compatibility

You could try to use an older version if you need IE support.

jackdh commented 6 years ago

For people also with this issue it can be solves by rolling back the promise to use callbacks.

request: function (url, body, success, error) {
    that = this;
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == XMLHttpRequest.DONE) {
            if (xmlhttp.status == 200) {
                var response = xmlhttp.responseText;
                var message = null;
                try {
                    message = JSON.parse(response);
                } catch (err) {
                    error(err);
                    return;
                }
                success(message);
            } else {
                error(new Error('status_' + xmlhttp.status));
            }
        }
    };

    xmlhttp.open("POST", url, true);
    xmlhttp.setRequestHeader("Content-Type", "application/json");
    xmlhttp.send(JSON.stringify(body));

}
getHistory: function (guid) {
    that = this;
    if (that.guid) {
        that.request('/botkit/history', {user: that.guid}, function(history) {
            if (history.success) {
                that.trigger('history_loaded', history.history);
            } else {
                that.trigger('history_error', new Error(history.error));
            }
        }, function(err) {
            that.trigger('history_error', err);
        });
    }
},
webhook: function (message) {
    that = this;

    that.request('/botkit/receive', message, function(data) {
        that.trigger(data.type, data);
    }, function(data) {
        that.trigger('webhook_error', data);
    });
},

I'm also currently working on converting this project to use Socket.io due to the nice fall backs it has to older browsers, it's working exceptionally well so might be worth a discussion to include it?

benbrown commented 6 years ago

@jackdh yes, please send a pull request with your Socket.io support!

jackdh commented 6 years ago

Sure I'm still cleaning up bot.js and client.js, however I've pushed the new Sockets.js to my fork

rajasekaran-k commented 6 years ago

Hi All, I included Polyfill js and it worked like a charm without any code changes!