forked from TheLastProject/mycroft-WebUI
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
451 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# auto add labels to PRs | ||
on: | ||
pull_request_target: | ||
types: [ opened, edited ] | ||
name: conventional-release-labels | ||
jobs: | ||
label: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: bcoe/conventional-release-labels@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: Stable Release | ||
on: | ||
push: | ||
branches: [master] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
publish_stable: | ||
uses: TigreGotico/gh-automations/.github/workflows/publish-stable.yml@master | ||
secrets: inherit | ||
with: | ||
branch: 'master' | ||
version_file: 'hivemind_chatroom/version.py' | ||
setup_py: 'setup.py' | ||
publish_release: true | ||
|
||
publish_pypi: | ||
needs: publish_stable | ||
if: success() # Ensure this job only runs if the previous job succeeds | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: dev | ||
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. | ||
- name: Setup Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: "3.11" | ||
- name: Install Build Tools | ||
run: | | ||
python -m pip install build wheel | ||
- name: version | ||
run: echo "::set-output name=version::$(python setup.py --version)" | ||
id: version | ||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | ||
with: | ||
tag_name: V${{ steps.version.outputs.version }} | ||
release_name: Release ${{ steps.version.outputs.version }} | ||
body: | | ||
Changes in this Release | ||
${{ steps.changelog.outputs.changelog }} | ||
draft: false | ||
prerelease: true | ||
commitish: dev | ||
- name: Build Distribution Packages | ||
run: | | ||
python setup.py sdist bdist_wheel | ||
- name: Publish to Test PyPI | ||
uses: pypa/gh-action-pypi-publish@master | ||
with: | ||
password: ${{secrets.PYPI_TOKEN}} | ||
|
||
|
||
sync_dev: | ||
needs: publish_stable | ||
if: success() # Ensure this job only runs if the previous job succeeds | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. | ||
ref: master | ||
- name: Push master -> dev | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
name: Release Alpha and Propose Stable | ||
|
||
on: | ||
pull_request: | ||
types: [closed] | ||
branches: [dev] | ||
|
||
jobs: | ||
publish_alpha: | ||
if: github.event.pull_request.merged == true | ||
uses: TigreGotico/gh-automations/.github/workflows/publish-alpha.yml@master | ||
secrets: inherit | ||
with: | ||
branch: 'dev' | ||
version_file: 'hivemind_chatroom/version.py' | ||
setup_py: 'setup.py' | ||
update_changelog: true | ||
publish_prerelease: true | ||
changelog_max_issues: 100 | ||
|
||
notify: | ||
if: github.event.pull_request.merged == true | ||
needs: publish_alpha | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Send message to Matrix bots channel | ||
id: matrix-chat-message | ||
uses: fadenb/matrix-chat-message@v0.0.6 | ||
with: | ||
homeserver: 'matrix.org' | ||
token: ${{ secrets.MATRIX_TOKEN }} | ||
channel: '!jImYhOcJWVpvCRsDjc:matrix.org' | ||
message: | | ||
new ${{ github.event.repository.name }} PR merged! https://github.com/${{ github.repository }}/pull/${{ github.event.number }} | ||
publish_pypi: | ||
needs: publish_alpha | ||
if: success() # Ensure this job only runs if the previous job succeeds | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: dev | ||
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. | ||
- name: Setup Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: "3.11" | ||
- name: Install Build Tools | ||
run: | | ||
python -m pip install build wheel | ||
- name: version | ||
run: echo "::set-output name=version::$(python setup.py --version)" | ||
id: version | ||
- name: Build Distribution Packages | ||
run: | | ||
python setup.py sdist bdist_wheel | ||
- name: Publish to Test PyPI | ||
uses: pypa/gh-action-pypi-publish@master | ||
with: | ||
password: ${{secrets.PYPI_TOKEN}} | ||
|
||
|
||
propose_release: | ||
needs: publish_alpha | ||
if: success() # Ensure this job only runs if the previous job succeeds | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout dev branch | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: dev | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Get version from setup.py | ||
id: get_version | ||
run: | | ||
VERSION=$(python setup.py --version) | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
- name: Create and push new branch | ||
run: | | ||
git checkout -b release-${{ env.VERSION }} | ||
git push origin release-${{ env.VERSION }} | ||
- name: Open Pull Request from dev to master | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
# Variables | ||
BRANCH_NAME="release-${{ env.VERSION }}" | ||
BASE_BRANCH="master" | ||
HEAD_BRANCH="release-${{ env.VERSION }}" | ||
PR_TITLE="Release ${{ env.VERSION }}" | ||
PR_BODY="Human review requested!" | ||
# Create a PR using GitHub API | ||
curl -X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: token $GITHUB_TOKEN" \ | ||
-d "{\"title\":\"$PR_TITLE\",\"body\":\"$PR_BODY\",\"head\":\"$HEAD_BRANCH\",\"base\":\"$BASE_BRANCH\"}" \ | ||
https://api.github.com/repos/${{ github.repository }}/pulls | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# HiveMind - Flask Chat Room | ||
|
||
 | ||
|
||
A multi-user Flask chatroom template for [HiveMind](https://github.com/OpenJarbas/HiveMind-core). | ||
|
||
This simple WebUI allows you to securely interact with your OpenVoiceOS instance through [HiveMind](https://github.com/OpenJarbas/HiveMind-core). | ||
|
||
 | ||
|
||
This is a reference implementation for integrating the HiveMind server-side without requiring users to provide credentials. | ||
|
||
For client-side (JavaScript) connection, check out [HiveMind-webchat](https://github.com/OpenJarbas/HiveMind-webchat). | ||
|
||
## Installation | ||
|
||
Install the package using `pip`: | ||
|
||
```bash | ||
$ pip install hivemind-flask-chatroom | ||
``` | ||
|
||
## Running the Application | ||
|
||
To run the chatroom, use the following command: | ||
|
||
```bash | ||
$ hivemind-flask-chatroom --port 8985 | ||
``` | ||
|
||
> Note: HiveMind credentials are read from your identity file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +0,0 @@ | ||
from twisted.internet import reactor | ||
from jarbas_hive_mind import HiveMindConnection | ||
from jarbas_hive_mind.slave.terminal import HiveMindTerminal | ||
from jarbas_utils import create_daemon | ||
from jarbas_utils.log import LOG | ||
from jarbas_utils.messagebus import Message | ||
|
||
platform = "JarbasFlaskChatRoomV0.1" | ||
|
||
|
||
class MessageHandler: | ||
messages = {} | ||
|
||
@staticmethod | ||
def append_message(incoming, message, username, room): | ||
if room not in MessageHandler.messages: | ||
MessageHandler.messages[room] = [] | ||
MessageHandler.messages[room].append({'incoming': incoming, | ||
'username': username, | ||
'message': message}) | ||
|
||
@staticmethod | ||
def get_messages(room): | ||
return MessageHandler.messages.get(room, []) | ||
|
||
|
||
class JarbasWebTerminal(HiveMindTerminal): | ||
_autorun = False | ||
|
||
# terminal | ||
def say(self, utterance, username="Anon", room="general"): | ||
MessageHandler.append_message(False, utterance, username, room) | ||
msg = {"data": {"utterances": [utterance], | ||
"lang": "en-us"}, | ||
"type": "recognizer_loop:utterance", | ||
"context": {"source": platform, | ||
"room": room, | ||
"user": username, | ||
"destination": "hive_mind", | ||
"platform": platform}} | ||
self.send_to_hivemind_bus(msg) | ||
|
||
def speak(self, utterance, username="Mycroft", room="general"): | ||
MessageHandler.append_message(True, utterance, username, room) | ||
|
||
# parsed protocol messages | ||
def handle_incoming_mycroft(self, message): | ||
assert isinstance(message, Message) | ||
if message.msg_type == "speak": | ||
room = message.context["room"] | ||
user = message.context["user"] | ||
utterance = message.data["utterance"] | ||
self.speak(utterance, room=room) | ||
elif message.msg_type == "hive.complete_intent_failure": | ||
LOG.error("complete intent failure") | ||
room = message.context["room"] | ||
user = message.context["username"] | ||
utterance = "I don't know how to answer that" | ||
self.speak(utterance, room=room) | ||
|
||
def run(self): | ||
reactor.run() | ||
|
||
def run_threaded(self): | ||
create_daemon(reactor.run, args=(False,)) | ||
|
||
|
||
def get_connection(host="wss://127.0.0.1", | ||
port=5678, name="JarbasChatRoomTerminal", | ||
access_key="RESISTENCEisFUTILE", | ||
crypto_key="resistanceISfutile", | ||
useragent=platform): | ||
con = HiveMindConnection(host, port) | ||
# internal flag, avoid starting twisted reactor | ||
con._autorun = False | ||
|
||
terminal = JarbasWebTerminal(crypto_key=crypto_key, | ||
headers=con.get_headers(name, access_key), | ||
useragent=useragent) | ||
|
||
return con.connect(terminal) | ||
Oops, something went wrong.