ryanvolum / offline-directline

Unofficial package to emulate the bot framework connector locally.
https://www.npmjs.com/package/offline-directline
78 stars 44 forks source link

Is directline port fixed at 3000? How to send messages to two bot services? #23

Closed shadabtamboli closed 6 years ago

shadabtamboli commented 6 years ago

I have two bot endpoints. Iam able to communicate with them from bot client but only one at a time.

I need to setup two bot clients which will talk to different directline ports. How can I host directline on on different port and communicate with two endpoints?

Also I am not able to host directlline on any other port other than 3000.

ryanvolum commented 6 years ago

@shadabtamboli, thanks for the request. In 1.2.4 I've updated the initializeRoutes function to take an optional port number, which will default to 3000. This should resolve your issue!

export const initializeRoutes = (app: express.Server, serviceUrl: string, botUrl: string, conversationInitRequired = true, port: number = 3000)

mattmazzola commented 6 years ago

Does this mean the port given in serviceUrl must match the value of port variable? I'm not sure how it works when these are different.

E.g.

directline.initializeRoutes(server, "http://127.0.0.1:3000", "http://127.0.0.1:3978/api/messages", 3001)

My understanding was seviceUrl was supposed to be the base url for the direct offline instance that is created. It just happened to work because the port was defaulted to 3000

shadabtamboli commented 6 years ago

It works only with port 3000. However you can go to js and replace 3000 with code to extract port number from base url.

On Tue, Jul 3, 2018, 4:36 AM Matt Mazzola notifications@github.com wrote:

Does this mean the port given in serviceUrl must match the value of port variable? I'm not sure how it works when these are different.

E.g.

serviceUrl: http://127.0.0.1:3000 port: 3000

My understanding was seviceUrl was supposed to be the base url for the direct offline instance that is created. It just happened to work because the port was defaulted to 3000

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ryanvolum/offline_dl/issues/23#issuecomment-401963730, or mute the thread https://github.com/notifications/unsubscribe-auth/AU9g4anWCCQPerZJOMPp-hElbQgS77zgks5uCqdzgaJpZM4ULzvn .

mattmazzola commented 6 years ago

It works only with port 3000

No, it works on other ports without modifying the .js. I ended up testing it. It's just that the serviceUrl should be constructed using the port you pass in. There are parts within the implementation of API that use the serviceUrl in responses so it needs this data, but in most cases it could have been constructed from the port as you see in this file:

https://github.com/ryanvolum/offline_dl/blob/961d129c1f68540d01232b3fe08a7469a1959d77/src/cmdutil.ts#L9

const port = 4366
const serviceUrl = `http://127.0.0.1:${port}`
directline.initializeRoutes(app, serviceUrl, botEndpoint, port)
ryanvolum commented 6 years ago

@shadabtamboli @mattmazzola is right here. You can optionally pass whatever port you like as your last parameter. This wasn't initially the case, so it seems a bit redundant now to declare your service url (with your port) and your port. A minimal refactor here would reduce confusion - will throw it on the backlog.