Check from which channel the user used to chat wit...
# 🤝help
f
Hi i need help to get from where the user came from e.g web chat or whatsapp. I have tried this code event.channel === 'messenger' || event.channel === 'twilio' || event.channel === 'slack' || event.channel === 'emulator' || event.channel === 'webchat' but when i test it just responds with "channel" on both whats and webchat
a
hey @fresh-window-29408 you might have better luck just using two equal signs
==
in your expressions. But you're on the right track with
event.channel
f
Thank you @acceptable-kangaroo-64719 let me try that.
@acceptable-kangaroo-64719 So i have tested this, and it seems to only return a response when i test on the emulator, when i test on web chat or whats app the response is just "channel"
a
interesting. If you make the bot say {{event.channel}} just for debugging, what does it say when you're on whatsapp?
f
On whatsapp It just responds with the word "channel" only on the emulator does it return "emulator", I have attached a photo of the conversation on whatsapp . Is there any other means to detect the channel?

https://cdn.discordapp.com/attachments/1142018643136364566/1142150887901499583/WhatsApp_Image_2023-08-18_at_19.29.52.jpeg

Hi @acceptable-kangaroo-64719 any joy with regards to getting a working solution for this?
a
@famous-zoo-73118 do you know?
f
@fresh-window-29408 @acceptable-kangaroo-64719 This will be fixed in a future update of all integrations (as unfortunately their initial and current version uses the word "channel" for the channel name in all integrations right now), but for the time being, you can just check for the existence of specific tags to know if the bot is running under a certain integration or not.
For example, to check if it's on Whatsapp, you can check if the
event.tags.user['whatsapp:userId']
tag is defined,
event.tags.user['webchat:id']
for webchat, or
event.tags.user['messenger:id']
for Messenger.
@fresh-window-29408 If you need to check for other channels, just check the
integration.definition.ts
file of our integrations which are open source and located here: https://github.com/botpress/botpress/tree/master/integrations
... and locate the
user.tags
node in the integration definition, which will list the tags available, which you can access through
event.tags.user
, the key is the integration name (defined at the top of the integration definition in the
name
property) followed by a colon and then followed by the tag name itself.

https://cdn.discordapp.com/attachments/1142018643136364566/1144279416919306381/image.png

f
@famous-zoo-73118 @acceptable-kangaroo-64719 Thank you so much for this, really helpful!
f
@User Is there now a way to detect the channel?
f
Yes! You can now get the name of the integration (what has been referred to as "channel" in this thread) through
event.integration
, which will contain a value like
webchat
,
whatsapp
,
messenger
, etc. Note that
event.channel
is to be used to know the channel of the integration that the message is occurring on, for example "thread" or "dm" in the case of the Slack integration, "pullRequest", "discussion", or "issue" in the case of the Github integration, or "channel" in the case of the default/main channel of all integrations.
f
Oh great! thank you very much!
8 Views