DialogFlow to Discord Bot connector

Hi all !

I am sorry but I have very low coding skills and I need to connect a DialogFlow agent to a Discord Bot.

Why I am here:
DialogFlow has an integration with Telegram so setting up a bot was quick, but now I am looking into PipeDream because I need to integrate it with a Discord Bot and there is no integration so far.

What is my problem:
This is more difficult that I thought initially. I am not sure what I am doing wrong, maybe I miss the entiere bot part, do I need to actually code a bot ?

So far I have created a bot on discord, the bot is offline :frowning:

I have also created a Pipedream workflow and connected both platforms credentials
From now on I am lost, I am missing something but I dont know what.

Thanks in advance for your help.
Laurent

Hi Laurent, welcome!

Can you tell me more about what you’re trying to do? What do you want your Discord bot to do?

I am setting up a simple Discord support chatbot, the bot is a DialogFlow agent with question and answer pairs, context and intents.

https://bot.dialogflow.com/4134dd58-bc3b-4865-b50e-d70428418e25

I found a template and I authenticated Discord and DialogFlow tokens

Now I have no idea what I should do next, do I need to use a cron job or where do I connect the HTTP API URL, or if I have to host a node.js somewhere.

Thanks for your answer !
Laurent

Hi Laurent,

Does your workflow need to run each time a user sends it a message on Discord? Or is it supposed to run on a different event?

Thanks,
Dylan

Thanks for your answer !

This will be a FAQ bot, the agent is already working.
Demo here: Snapshot
At first the bot need a Beta phase in 1-1 (You DM the bot and each message you send trigger an answer from the bot)

Then in the future we aim to make it public on our public Discord ?helpdesk channel by setting a command for explicit invocation, then if all these steps are really helping the users we can program it to respond to implicit invocations.

:wink:
Laurent

Hi Laurent,

Discord bots work a bit differently than bots in other apps like Slack in that Discord requires you to host an express-like app that serves as the bot and will be able to listen for all sorts of events (DMs to the bot, messages to channels, people entering/leaving the server, people using “Interactions” aka slash commands–and maybe buttons and widgets in the future whenever Discord decides to add those).

You use discord.js for this (https://discord.js.org/). What this means is that while you can use Pipedream to process event workflows (especially the particular Interactions webhook, which can pass data to a Pipedream source), the bot will still need to be hosted. Don’t forget to enable ingress for ports 443 and 80 on whatever server the bot is being hosted (could be a Heroku instance, could be on an EC2 instance, or your laptop, literally anywhere).

At minimum, the bot code could do this:

const Discord = require("discord.js");
const keys = require("./config/keys");
const client = new Discord.Client();

client.login(keys.bot_token);

// when the bot logs online, it will be in a "ready" state
client.on("ready", async () => {
  const channel = await client.channels.cache.get(CHANNEL_ID_HERE);
  let dt = new Date();
  const resp = await channel.send(`Bot has logged online at ${dt.toISOString()}`);
  console.log(`Logged in at ${dt.toISOString()}`);
});

client.on("message", async (message) => {
  try {
      // do whatever you wanna do here in terms of message listening server-wide
  } catch (error) {
    console.log(error);
  }
});

You can listen to messages (or other events) and then pass the payload to a Pipedream source to trigger your larger workflows there (in fact, that’s what I do).

One thing to particularly note: the latest discord.js package requires npm v16 env or so. The workflows on Pipedream currently support npm v14. I snapshotted discord.js in a release that still works with npm v14 environments here, so I require this specific package in Pipedream workflows: @n-h-n/discord.js-12.5.3 - npm

Hi NN,

Thanks for your extensive explaination, it will save me a lot of time, I will deep dive into this rabbit hole, I feel that FAQ bots existing on discord are quite dumb, this is why I try to setup this DialogFlow - Discord integration. The fact that it can crawl my FAQ on GitBook is a good value, that mean I need to maintain the FAQ only at one place, then tune the entities and intents on DialogFlow. But yeah, as a non-dev I am sweating a lot :slight_smile:
Thanks a lot for having helped me !


Yeahhhh ! Thanks a lot !