Webex-Email-Bot

A bot that can send email by taking in webex message chat input.

This email bot is built on Webex-Bot-Starter (https://github.com/WebexSamples/webex-bot-starter). Added one more "send-email" command and you can add this function in to start sending email. If you dont have a webex bot yet, refer to the Webex-Bot-Starter instruction. Use the chat function here to add email feature.

Release update

  • 16th Dec 2024 - First release of the script

Pre-requisite:-

Installation (if you have a working webex bot)

You only need "email-function-only.txt", the other file "index.js" is for your reference

Here are the steps to prepare and run the script:-

  1. Complete the prerequisites
  2. Installation - Clone the repo
git clone https://github.com/ciscoketcheon/Webex-Email-Bot.git
  1. Configuration - Edit your existing "index.js" file

    • Copy "email-function-only.txt" content, it is the main code for "send-email" function
    • Paste it anywhere in between function. A function starts with "framework.hears(" and ends with ");"
    • Recommend to paste it before the last catch-all function. Refer to the "index.js" here as reference
  2. One more modification needed is to update the x.x.x.x in the "send-email" function with your relay server IP address

   ...const command = `swaks --server x.x.x.x --from "${sender}...

Example update, say relay server IP address is 192.168.25.25. Relay server configuration server is beyond this guide.

   ...const command = `swaks --server 192.168.25.25 --from "${sender}...
  1. Save and re-run the bot script
npm start

Webex-bot Installation (from scratch)

If you have never installed a Webex bot before, suggest to follow this full guide -> https://developer.webex.com/blog/from-zero-to-webex-teams-chatbot-in-15-minutes

In summary, here are the steps from scratch:-

  1. Complete the prerequisites, e.g. prepare and copy webex bot auth-token, ngrok account sign-up and prep the auth-token, pre-install swaks, prep SMTP relay
  2. Clone the Webex bot starter repo
git clone https://github.com/WebexSamples/webex-bot-starter.git && cd webex-bot-starter
  1. Start ngrok webhook, find its better with EU region
ngrok http 7001 --region=eu

Optional -- Do explore using a separate screen or terminal for ngrok and npm, try run "screen" from linux to spawn a new one, or do a "screen -r" to show the running screens, and do a "screen -r XXXX" to restore a screen (XXXX is the screen number). If you want to leave current screen session and jump back to main session, do a Ctrl+A+D key combination.

  1. Copy ".env.local" to a new file ".env", update the ".env" file with ngrok webhook URL (from #3) and webex bot auth-token (from #1)

  2. In another folder, clone this repo

git clone https://github.com/ciscoketcheon/Webex-Email-Bot.git
  1. Configuration - Edit your existing "index.js" file
    • Copy "email-function-only.txt" content, it is the main code for "send-email" function
    • Paste it anywhere in between function. A function starts with "framework.hears(" and ends with ");"
    • Recommend to paste it before the last catch-all function. Refer to the "index.js" here as reference
  2. One more modification needed is to update the x.x.x.x in the "send-email" function with your relay server IP address
   ...const command = `swaks --server x.x.x.x --from "${sender}...

Example update, say relay server IP address is 192.168.25.25. Relay server configuration server is beyond this guide.

   ...const command = `swaks --server 192.168.25.25 --from "${sender}...
  1. Save and re-run the bot script (from webex-bot-starter folder)
npm start

Sending email with the bot

Look for your bot from webex teams, start by sending the bot anything, it shall response with suggested usage, example:-

Usage:
	•	framework: (learn more about the Webex Bot Framework)
	•	info: (get your personal details)
	•	space: (get details about this space)
	•	say hi to everyone: (everyone gets a greeting using a call to the Webex SDK)
	•	card me: (a cool card!)
	•	reply: (have bot reply to your message)
	•	help: (what you are reading now)
	•	send-email: (send-email|Sender email address|Recipient email address|Subject Here|Email body text here)


Powered by Webex Node Bot Framework - https://github.com/webex/webex-node-bot-framework

Try to send a email following the syntax, example:-

send-email sender@test.com|recipient@domain.com|any subject|any email body content

You will receive response from the bot if the email sent successfully.

References

Webex bot -> https://developer.webex.com/blog/from-zero-to-webex-teams-chatbot-in-15-minutes

Webex bot github -> https://github.com/WebexSamples/webex-bot-starter

View code on GitHub

Code Exchange Community

Get help, share code, and collaborate with other developers in the Code Exchange community.View Community
Disclaimer:
Cisco provides Code Exchange for convenience and informational purposes only, with no support of any kind. This page contains information and links from third-party websites that are governed by their own separate terms. Reference to a project or contributor on this page does not imply any affiliation with or endorsement by Cisco.